On Wed, Aug 21, 2019 at 10:02 AM EnterpriseJacksonBeansFrameworkCE
<[email protected]> wrote:
>
>
> I am trying to map json dictionary of objects with known structure to POJO
> under jackson control:
>
> import com.fasterxml.jackson.annotation.JsonProperty;
>
>
> public class GetListOfRecordsResponse {
>
> @JsonProperty("recordsCount")
>
> private Integer recordsCount; // Works always
>
>
> @JsonProperty("records")
>
> private Map<String, GeneratedRecordObject> records = new HashMap<>(); //
> Should also work without "records" (see second json)
>
> }
>
>
> It works properly for following (fake) json response:
>
> {
>
> "recordsCount": 2,
>
> "records": {
>
> "-1": {
>
> ...
>
> },
>
> "1": {
>
> ...
>
> }
>
> }
>
>
> How can I modify GetListOfRecordsResponse (JsonProperty attribute? Using
> another attribute?) to allow parsing following real world JSON response
>
>
> {
>
> "recordsCount": 2,
>
> "-1": {
>
> ...
>
> },
>
> "1": {
>
> ...
>
> }
>
> }
>
>
>
> Removing records does not work properly: the deserialized records is empty.
>
> How can I solve this problem?
I am not 100% sure, but one thing that might work is to simply force
ignoral of `recordsCount` entry, something like:
public class GetListOfRecordsResponse {
@JsonIgnoreProperties({ "recordsCount" })
@JsonProperty("records")
private Map<String, GeneratedRecordObject> records;
}
-+ Tatu +-
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/jackson-user/CAL4a10iZoTgbzis-Vw_yf4oezxU-49nbFXiV37PS8ZH6XA%3DEaQ%40mail.gmail.com.