Skip to content

Unable to deserialize a pojo with IonStruct #571

@seadbrane

Description

@seadbrane

I am not seeing a good option to serialize/deserialize a simple Pojo with a null IonStruct.

The issue is that by default a null IonStruct gets serialized to null but due to this change #296 that gets converted to a an IonNull, and fails with argument type mismatch.

Failing testing:

  public static class Pojo {    
        @JsonCreator
        public Pojo(@JsonProperty("name") String name, @JsonProperty("data") IonStruct data) {   
            this.name = name;
            this.data = data;
        }
        public String name;
        public IonStruct data;
        
        
        @Override
        public int hashCode() {
            return Objects.hash(data, name);
        }
        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            Pojo other = (Pojo) obj;
            return Objects.equals(data, other.data) && Objects.equals(name, other.name);
        }
    }

    private final IonSystem ionSystem = IonSystemBuilder.standard().build();
    private final IonValueMapper mapper = new IonValueMapper(ionSystem);

    @Test
    public void testRoundTrip() throws JsonProcessingException {
        Pojo p = new Pojo("test", null);
        String value =  mapper.writeValueAsString(p);
        Assert.assertEquals("{name:\"test\",data:null}", value);
        Pojo p2 = mapper.readValue(value, Pojo.class);
        Assert.assertEquals(p, p2);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions