1

JSON :

"ABCD": [  
  {  
    "xyz": 3,  
    "abc": 4,  
    "info": {  
      "MY_TITLE": "Hello World",  
      "MY_DESCRIPTION": "New to the world"  
    }
  }
  ...similar sub parts
]

In the case above, since info is another object in itself, the sub string are in upper case. My mapping to these in java goes on as :

@JsonProperty("xyz")
private Integer xyz;

@JsonProperty("abc")
private Integer abc;

@JsonProperty("MY_TITLE")
private String myTitle;

@JsonProperty("MY_DESCRIPTION")
private Long myDescription;

Need some documents and practices over the JSON creation and mapping the same on the java.

  1. Is the JSON field naming convention inappropriate?

    OR/AND

  2. Is the JsonProperty mapping incorrect?
Naman
  • 27,789
  • 26
  • 218
  • 353

1 Answers1

1

Well, the mapping seems inappropriate to me. What you should have is

// ...
@JsonProperty("xyz")
private Integer xyz;

@JsonProperty("abc")
private Integer abc;

@JsonProperty("info")
private MyInfoClass info;
// ...

then, the (separate) MyInfoClass :

public class MyInfoClass {

  @JsonProperty("MY_TITLE")
  private String myTitle;

  @JsonProperty("MY_DESCRIPTION")
  private Long myDescription;

  // getters, setters and so on
}

EDIT : as for the naming convention, I don't think there is a single widely accepted way, but the most common conventions I know of are camelCase and snake_case (both using non-capital letters). See this question for more info : JSON Naming Convention

Community
  • 1
  • 1
francesco foresti
  • 2,004
  • 20
  • 24
  • appreciate the idea of separating the classes, but for a broader project wouldn't it be different practice to follow camelCase in one class and snake_case in another? – Naman Jun 01 '16 at 07:57