boonproject / boon

Simple opinionated Java for the novice to expert level Java Programmer. Low Ceremony. High Productivity.
http://richardhightower.github.io/site/Boon/Welcome.html
Apache License 2.0
520 stars 102 forks source link

Parsing objects into another object #374

Closed cristiammercado closed 4 years ago

cristiammercado commented 7 years ago

Hi,

I have a problem deserializing this class:

public class ResponseData {

    private int status;
    private boolean success;
    private Object data;
    private ErrorResponse error;

    public ResponseData() {
        this(200, true, null, null);
    }

    public ResponseData(int status, boolean success, Object data, ErrorResponse error) {
        this.status = status;
        this.success = success;
        this.data = data;
        this.error = error;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public ErrorResponse getError() {
        return error;
    }

    public void setError(ErrorResponse error) {
        this.error = error;
    }

    public ResponseData ok(Object data) {
        this.status = Response.Status.OK.getStatusCode();
        this.success = true;
        this.data = data;
        this.error = null;

        return this;
    }

    public ResponseData error(ErrorResponse error) {
        this.status = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
        this.success = false;
        this.data = null;
        this.error = error;

        return this;
    }

}

This class is serialized in an API on JAX-RS, but when I going to deserialize it in the client in Java with Boon, I get the following exception:

org.boon.Exceptions$SoftenedException: fieldName data of class class any.package.ResponseData had issues for value MAP for field FieldInfo [name=data, type=class java.lang.Object, parentType=class any.package.ResponseData]

 CAUSE java.lang.NullPointerException :: null
    at org.boon.Exceptions.handle(Exceptions.java:128)
    at org.boon.core.reflection.MapperSimple.fromValueMap(MapperSimple.java:1139)
    at org.boon.json.JsonMappingParser.finalExtract(JsonMappingParser.java:208)
    at org.boon.json.JsonMappingParser.parse(JsonMappingParser.java:200)
    at org.boon.json.implementation.ObjectMapperImpl.readValue(ObjectMapperImpl.java:67)
    at org.boon.json.implementation.ObjectMapperImpl.fromJson(ObjectMapperImpl.java:278)
    at org.boon.json.JsonFactory.fromJson(JsonFactory.java:60)
       ...
Caused by: java.lang.NullPointerException
    at org.boon.core.reflection.MapperSimple.fromValueMapHandleValueCase(MapperSimple.java:1217)
    at org.boon.core.reflection.MapperSimple.fromValueMap(MapperSimple.java:1134)
    ... 8 more

I don't have any idea what is the problem.

Thanks in advance!