0

Getting

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: 

Unrecognized field "operationMessage" (class worker.lib.message.OperationMessage), not marked as ignorable (9 known properties: "packageMessage", "sourceAsset", "operation", "publishMessage", "requestId", "remixMessage", "targetAsset", "jobId", "intermediates"])
    
 at [Source: (String)"{"operationMessage":{"sourceAsset":{"path":"/a/b/c.txt","repoId":"testId","region":"va6"},"targetAsset":{"path":"/folder4","repoId":"id2","region":"va6"},"jobId":"7c540211d1054442940211d10594426e","intermediates":false}}"; line: 1, column: 22] (through reference chain: 
worker.lib.message.OperationMessage["operationMessage"])

My OperationMessage Class is

@JsonInclude(JsonInclude.Include.NON_NULL)
@Data //generates getter and setters
public class OperationMessage {
  
  @JsonProperty(value = "jobId")
  private String jobId;
  
  @JsonProperty(value = "operation")
  private Operation operation;
  
  @JsonProperty(value = "intermediates")
  private Boolean intermediates; //for copy-move 
  
  private AssetProperties sourceAsset;
  
  private AssetProperties targetAsset;
  
  private PublishMessage publishMessage; //fields related to publish Operation. 
  
  private RemixMessage remixMessage; //fields related to remix Operation.
  
  private PackageMessage packageMessage;//fields related to package Operation

  private String requestId;

  @Override
  public String toString() {
    return "OperationMessage [jobId=" + jobId + ", operation=" + operation + "]";
  }
  

}

Can someone suggest what is the issue here?

Ankur Garg
  • 2,553
  • 8
  • 30
  • 41

2 Answers2

1

Some things you should do are the following:

1) Add getters & setters for the member variables of your class

2) Add a default constructor public class OperationMessage { }

3) Implement the Serializable public class OperationMessage implements Serializable

4) Add the @JsonIgnoreProperties(ignoreUnknown = true) annotation to your POJO

NickAth
  • 1,089
  • 1
  • 14
  • 35
  • So I do have getters and setters . I use lombok annotations which provide them. – Ankur Garg Apr 01 '19 at 15:59
  • Did you do all the rest steps? – NickAth Apr 01 '19 at 16:00
  • Actually default constructor is also there. @JsonIgnoreProperties(ignoreUnknown = true) has to be applied on class level ?. Also, wont @JsonInclude(JsonInclude.Include.NON_NULL) mean the same? – Ankur Garg Apr 01 '19 at 16:02
  • I am using same object while serializing and it ignores NULL values. – Ankur Garg Apr 01 '19 at 16:04
  • {"operationMessage":{"jobId":"4ad9695d224740b499695d224700b474","intermediates":false,"sourceAsset":{"path":"/folder1/folder2/a.txt","repoId":"urn:uuid:fe86e84b-d426-4e5a-b849-3381f06aae18","region":"va6"},"targetAsset":{"path":"/folder4","repoId":"urn:uuid:fe86e84b-d426-4e5a-b849-3381f06aae18","region":"va6"}}} – Ankur Garg Apr 01 '19 at 16:05
  • Yes the JsonIgnoreProperties(ignoreUnknown=true) has to be applied on the class level, no they are not the same, you can check this https://stackoverflow.com/questions/39005703/jackson-annotations-difference-between-jsonignorepropertiesignoreunknown-true – NickAth Apr 01 '19 at 16:08
  • Ok So I tried with JsonIgnoreProperties(ignoreUnknown=true) and it gives same exception which is not unexpected as I am serializing and deserializing same object. It would have been handy had I serialized a different POJO and deserialized a different one. That is not the case here. Unfortunately, the problem still remains for me :( – Ankur Garg Apr 01 '19 at 16:17
  • How do you try to deserialize the JSON to the java object? – NickAth Apr 01 '19 at 16:34
  • Actually, there was a mistake at my end. Both JsonIgnore and JsonInclude will work. There was some other bug in my code. Thanks for all your help Nick :) and your patience in answering my questions. – Ankur Garg Apr 01 '19 at 17:33
0

You don't have getters and setters... Or change these fields to be public.

Hua
  • 666
  • 2
  • 9
  • 21