1

I have a string delimited by a semi-colon

value1; value2; value3; etc..

I am using Jackson ObjectMapper to deserialize the json response into a POJO but am having issues figuring out how to tell Jackson that it should split this string property on ';'

Is this feature supported by Jackson?

Hoping for something like

public class POJO {
    @JsonFormat(shape = JsonFormat.Shape.ARRAY, delimitOn = ";")
    private List<String> category;
}

I also tried my own deserializer based on this answer but Jackson complained about not being able to convert String to List - maybe I did this wrong?

public class DelimitedStringDeserializer extends StdDeserializer<List<String>> {

    protected DelimitedStringDeserializer() {
        super(List.class);
    }

    @Override
    public List<String> deserialize(org.codehaus.jackson.JsonParser jp, org.codehaus.jackson.map.DeserializationContext ctxt) throws IOException, org.codehaus.jackson.JsonProcessingException {
        return Arrays.asList(jp.getText().split(";"));
    }
}

0 Answers0