Hey,

May somebody please have a look at the following problem? 

It is about nested polymorphism into another object and it fails on 
nullPointerException when it meets attribute using abstract class 
declaration.

In other words it fails to determine which concrete entity to use when 
parent entity for that attribute is using abstract entity.Or it never does 
- since it never enter the deserializer.

Problem:
1) I am acting as a proxy, getting requests from UI and forwarding them to 
the other system.
2) Before sending the response back to the UI I am mapping it to my local 
DTO schema of that remote system – so we can have power over what we send 
to the UI..
3) That system sends completely ambiguous data structure depending on their 
count. Imagine entity object with attribute member. If that member is only 
one, that attribute is object. If more than one, then that attribute is 
array.

So you see my point now.. I have 2 DTOs for this case – 1 is when member is 
object, 2 is when member is array and they both inherit from abstract 
parent.

But this isnt all.. That schema I just described is wrapped into another 
Wrapper object where I am using their abstract parent for the attribute 
type. That wrapper is needed because that remote system returns 0 or 1 or 
>1 objects in the very same attribute of that wrapper but of different type 
also. So it looks like this:

public class Wrapper {
    @JsonProperty(“wrapper”)
    private AbstractWrapper wrapper;
}

public abstract class AbstractWrapper {
}

public class WrapperString extends AbstractWrapper {
    @JsonProperty(“dto”)
    private String dto;
}

public class WrapperObject extends AbstractWrapper{
    @JsonProperty(“dto”)
    private AbstractDTO dto;
}

public class WrapperList extends AbstractWrapper{
    @JsonProperty(“dto”)
    private List<AbstractDTO> dto;
}

public abstract class AbstractDTO {
}

public class Impl1DTO extends AbstractDTO {
    @JsonProperty(“member”)
    private String member;
}

public class Impl2DTO extends AbstractDTO {
    @JsonProperty(“member”)
    private List<String> member;
}


I have both deserializers for this registered. It will check if member is 
type of Object or Array or String and determine the concrete class. This 
works for the Wrapper Polymorphism. However it doesnt for nested 
polymorphism. It never enters that deserializer no matter what I try.. And 
when deserializing it fails on null pointer exception on @JsonProperty(“dto
”)

Here is also more detailed stackoverflow 
<https://stackoverflow.com/questions/51309359/jackson-deserialization-with-polymorphism-nested-into-polymorphism-aka-more-th>
 thread 
I created for this.

I will appreciate any inputs for this. Thanks, Michal

-- 
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