JsonMappingException: Not a map, not an array or not an enum

839 views
Skip to first unread message

Matej

unread,
Mar 16, 2020, 6:02:57 AM3/16/20
to jackson-user
Hello,

I am working on a rest api application and i have some problems with the code. Part of code that is problematic is:

    @JsonValue
    public String serialize() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(this);
    }

This returns not an enum. The current object is an extend of avro schema. I also tried:

    @JsonValue
    public String serialize() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.writeValueAsString(getUserData());
    }

Where user data is an actual avro object. I dont understand what do these error mean. Can someone explain? Also, is there a better way to return an avro object combined with other parameters?

Thanks

Matej

unread,
Mar 16, 2020, 6:28:41 AM3/16/20
to jackson-user

Here is the full example:

public class PaginatedUserData extends UserDataAvro {

    @JsonValue
    public String serialize() throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();

        HashMap<String, String> map = new HashMap<>();
        map.put("test", "5");
        return mapper.writeValueAsString(map);
    }
}

Returns:

Could not write JSON: Not an array 

Reply all
Reply to author
Forward
0 new messages