Jackson annotations are ignored

I am trying to use Jackson annotations to rename some json shortcuts created during serialization. The annotations all compile fine, and when I run, Jackson serialization works, except that Jackson annotations are completely ignored. Even basic ones like @JsonIgnore or @JsonProperty do not affect json's response. The libraries that I have in my build path:

jsr311-qpi-1.1.1.jar jackson-[core|databind|annotations]-2.2.0.jar 

I work in Eclipse, launching an external berth program with setting up an external program as:

 Location: .../apache-maven-2.2.1/bin/mvnDebug.bat working Directory: ${workspace_loc:/ohma-rest-svr} Arguments: jetty:run 

with the configuration of the remote Java application installed as:

 Host: localhost Port: 8000 

Without error messages that you can work with, I will lose a little things to try. Any ideas would be appreciated.

Here are some code examples from the class that I need to serialize:

 @XmlRootElement(name="ads-parameter") public class DefineParameterResponse { private Date _createdAt = new Date(); @JsonProperty("created-at") @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd,HH:00", timezone="CET") @XmlElement public String getCreatedAt() { return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(_createdAt); } @JsonProperty("created-at") public void setCreatedAt(Date createdAt) { this._createdAt = createdAt; } private String _dataTitle1 = "Default Title1"; @XmlElement @JsonProperty("data-title-1") public String getDataTitle1() { return _dataTitle1; } @JsonProperty("data-title-1") public void setDataTitle1(String dataTitle1) { this._dataTitle1 = dataTitle1; } @XmlElement @JsonProperty("data-title-2") public String getDataTitle2() { return _dataTitle2; } @JsonProperty("data-title-2") public void setDataTitle2(String dataTitle2) { this._dataTitle2 = dataTitle2; } 
+4
source share
1 answer

One of the relatively common reasons is an attempt to use the โ€œwrongโ€ set of annotations: Jackson 1.x and Jackson 2.x comments in different Java packages, and the data binding should correspond to the main version. This design has the advantage of allowing you to use versions 1.x and 2.x side by side, without class loading conflicts; but the disadvantage is that you have to make sure that you have the appropriate versions.

The biggest problem is the use of frameworks: many JAX-RS implementations (such as Jersey) still use Jackson 1.x. Therefore, I assume that you can use Jackson 1.x indirectly, but add Jackson 2.x annotations. If so, you need to use 1.x annotations (the ones under org.codehaus.jackson ).

+23
source

Source: https://habr.com/ru/post/1501337/


All Articles