I am working on a rest api application and i have some problems with the code. I want to return an object that extends avro schema and adds HATEOAS links to the response. I did some investigation and as it turns out i need custom serializer for object.
Part of code that is problematic is:
@JsonValue
public String serialize() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(this);
}
This returns
Could not write JSON: 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());
}
It returns:
Could not write JSON: Not an array
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
EDIT:
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
objectMapper
from? – Bernardabernardi