0

I want to deserialize this json string

{"value":"Y"}

to this object

public class Data {
    byte value;

    public byte getValue() {
        return value;
    }

    public void setValue(byte value) {
        this.value = value;
    }       
}




ObjectMapper mapper = new ObjectMapper();
Data data =  mapper.readValue(js, Data.class);

it works when in json string I put an ascii code {"value":89}

But I want to use char value.

Main problem is that Data class is legacy class, and I can't add @JsonDeserialize annotation inside it.

Any other option?

yuris
  • 1,109
  • 4
  • 19
  • 33
  • Create a new class with needed types and wrap legacy class in it. – Andremoniy Jan 10 '18 at 09:08
  • You have to use something else than ``Data`` because that is what limits the type to ``byte``. – f1sh Jan 10 '18 at 09:09
  • Possible duplicate of [Setting up JSON custom deserializer](https://stackoverflow.com/questions/6553051/setting-up-json-custom-deserializer) – kryger Jan 10 '18 at 09:12

0 Answers0