Jay
Jay

Reputation: 2454

POJO with slash in variable name conversion to JSON conversion using jackson

I am trying to use jackson to convert a pojo to json. The json that I need to generate has the following structure -

"paragraphs": [
  {
    "text": "This is a test text",
    "page/pages": "1/56",
  }

Notice how one of the items is "page/pages", but I cannot directly creating a variable name in POJO with the same name. How do I generate the JSON in the above format if slash is not allowed in variable name in java?

Upvotes: 0

Views: 252

Answers (1)

J0B
J0B

Reputation: 1648

Try an annotation e.g.

@JsonProperty("page/pages")
public String pages;

Upvotes: 1

Related Questions