JayMash JayMash - 2 months ago 7
JSON Question

jackson2 - unexpected field in JSON

I'm trying to write a JSON from a java object. Everything works fine until I write the values to a String using the ObjectMapper. The String shows an unexpected field in the JSON document called "map".

I want this:

{
"name": [
{
"a": "1",
"b": "2",
"c": "3",
"d": "4",
"e": "5",
"f": "6"
}
]
}


I get this:

{
"name": [
{
"map": {
"a": "1",
"b": "2",
"c": "3",
"d": "4",
"e": "5",
"f": "6"
}
]
}


This is the class where I've defined the Object I want to convert to JSON:

public class SomeClass{
private List<JSONObject> name;

//getters, setters
}


Can anyone help me?

Answer

I've solved the problem. I just created an array of object and then I've serialized it with jackson.

private Bla[] bla;
// getters and setters

Class Bla:

private String a;
private String b;
private String c;
...
// getters and setters

Thank you for everything.

Jon