naXa stands with Ukraine
naXa stands with Ukraine

Reputation: 37936

@JsonProperty name with spaces

Is it allowed to have spaces in @JsonProperty name? i.e.

@JsonProperty("Jon Snow")
private String jonSnow = "Lord";

// getter & setter are omitted

I expect to get the following output:

{
   "Jon Snow" : "Lord"
}

But the actual result is:

{
   "jonSnow" : "Lord"
}

I use jackson-core v2.8.8, jackson-databind v2.8.8.1, and jackson-annotations v2.8.8.

Upvotes: 3

Views: 2878

Answers (1)

naXa stands with Ukraine
naXa stands with Ukraine

Reputation: 37936

The problem was that I was using @JsonProperty annotation from the wrong Jackson library.

I had import org.codehaus.jackson.annotate.JsonProperty; (Jackson v1) which I had to change to import com.fasterxml.jackson.annotation.JsonProperty; (Jackson v2), to be consistent with the library I was using.

I've found the answer in comments to this question: @JsonProperty not working as expected

Upvotes: 5

Related Questions