3breadt / dd-plist

A java library providing support for ASCII, XML and binary property lists.
Other
258 stars 94 forks source link

NSArray to typed array with polymorphism #81

Closed x-c4mp3r closed 9 months ago

x-c4mp3r commented 1 year ago

My problem is the following:

public class PayloadDto {
    private List<PayloadContentDto> payloadContent = new ArrayList<>();
}

public class PayloadContentDto {
    protected String payloadType;
}

public class A extends PayloadContentDto {
   private String aProperty;
}

public class B extends PayloadContentDto {
   private String bProperty;
}

public PayloadDto getDtoFromPListByteArray(byte[] content) {
...
    NSObject parse = PropertyListParser.parse(content);
    PayloadDto payloadDto = parse.toJavaObject(PayloadDto.class);
...
}

When calling getDtoFromPListByteArray the payloadContent list contains these types:

[
class PayloadContentDto(payloadType="aType"),
class PayloadContentDto(payloadType="bType"),
]

instead of these expected ones:

[
   class A(payloadType="aType", aProperty="a's property"),
   class B(payloadType="bType", bProperty="b's property"),
]

Is there any way to achive the proper class convertion?

Something like Jackson annotations

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "payloadType", visible = true)
@JsonSubTypes({
        @JsonSubTypes.Type(value = A.class, name = "aType"),
        @JsonSubTypes.Type(value = B.class, name = "bType"),
})
3breadt commented 1 year ago

Polymorphism is not supported by the toJavaObject method as of now.

x-c4mp3r commented 1 year ago

Thank you for your answer.