0

I have a self-generated client response class:

import javax.json.bind.annotation.JsonbProperty;

    public class MyClass {
    
      @JsonbProperty("name-surname")
      private String nameSurname;
    
      //getter and setter
    }

the client response json is:

{
  "name-surname":"Jack Jones"
}

The problem is that the @JsonbProperty annotation does not work in this case and therefore the field is not read., is there a solution?

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Prodox21
  • 107
  • 1
  • 2
  • 9
  • I don't understand your problem statement. What special characters are you referring to? – Robert Harvey Apr 21 '22 at 12:47
  • You mean @JsonbProperty("nameSURNAME")` would have worked, the hyphen being the culprit? – Joop Eggen Apr 21 '22 at 12:59
  • @RobertHarvey yes, the output json of the service I consume expects the "-" in the name of the field and this causes the problem, the JsonbProperty does not recognize the field and does not deserialize – Prodox21 Apr 21 '22 at 13:54
  • @JoopEggen yes, mocking the answer by removing the "-" in the name of the output field, and also removing it from the JsonbProperty, the field is correctly deserialized – Prodox21 Apr 21 '22 at 13:56
  • Does this answer your question? [Unable to access JSON property with "-" dash](https://stackoverflow.com/questions/13869627/unable-to-access-json-property-with-dash) – Robert Harvey Apr 21 '22 at 14:35
  • @RobertHarvey unfortunately no, my problem is on java and not javascript, also the library used is import javax.json.bind.annotation.JsonbProperty and not JsonProperty – Prodox21 Apr 21 '22 at 15:07
  • Can you simply strip the JSON of hyphens? – Robert Harvey Apr 21 '22 at 17:58

0 Answers0