The very first suggestion, as always, is to make sure you use the latest
patch for minor version: in this case, 2.8.9.

Getting an `ArrayList` is a sign that type information is not available (it
is what is bound for `java.lang.Object` valued properties, from JSON Array).
But in this case I do not think you should have to enable default typing,
since you only want `body` to use polymorphic handling. You could instead
annotate it with `@JsonTypeInfo`.

Not sure if either of these will fix the problem but they are probably good
places to start.

-+ Tatu +-


On Tue, Aug 15, 2017 at 10:16 PM, vmaroli <[email protected]> wrote:

> Hi,
> Running into issue while deserializing a class with value of type Object.
> Java class is as following.
>
> public final class Message {
>
>     private final MessageHeader header;
>     private final Object body;
>
>     @JsonCreator
>     public <T> Message(@JsonProperty("header") MessageHeader header, 
> @JsonProperty("body") T body) {
>         this.header = header;
>         this.body = body;
>     }
>
>     public MessageHeader getHeader() {
>         return header;
>     }
>
>     public Object getBody() {
>         return body;
>     }
>
>     @JsonIgnore
>     public <T> T getBody(Class<T> objectType) {
>         if(objectType.isInstance(this.body)) {
>             return objectType.cast(this.body);
>         }
>         throw new Exception("Message body is not of type 
> "+objectType.toString());
>     }}
>
> Using Jackson 2.8.4 for serializing and deserializing the object in JSON
> format using a mapper enabled with DefaultTyping
> (mapper.enableDefaultTyping()). Running into problems while trying to
> retrieve the message body part using generic version of getBody method.
> Getting object of type java.util.ArrayList instead of the actual object
> type passed. Any suggestions on what is missing mapper configuration or any
> other ?
>
> Message.getBody is invoked as following.
>
> DataSet data = getDataSet();Message message = new 
> Message(header,data);...DataSet data = message.getBody(DataSet.class);
>
> JSON message is as following which when attempted to deserialize is giving
> problem.
>
> {
>   "header" : {
>     "hostId" : "XYZ",
>     "hostname" : "X-123456789",
>     "systemType" : "ABC"
>   },"
>   "body" : [ "com.foo.DataSet", {
>     "createTimestamp" : 1502859923155,
>     "records" : [ "java.util.ArrayList", [ {
>       "name" : "Running",
>       "timestamp" : 1502859923162,
>       "value" : true
>     }, {
>       "name" : "Command",
>       "timestamp" : 1502859923162,
>       "value" : false
>     } ] ]
>   } ]}
>
>
> [1] - https://stackoverflow.com/questions/45675200/json-
> deserialization-using-jackson-for-java-lang-object-returns-
> java-lang-arrayl
>
> Regards
> Vinu
>
> --
> You received this message because you are subscribed to the Google Groups
> "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to