2

I have a property like this:

    @CatalogExportField(columnName = "K", headerName = "catalog name")
private Boolean mpAvailable;

I need to get this as string while parsing in other class

   private CatalogExportDto convert(Variant variant, boolean willHaveProductTypeFields) {
    CatalogExportDto dto = new CatalogExportDto()


        .setMpAvailable(variant.isMpAvailable())

But here it is boolean.

I need to do somethng like this i think.

    @JsonDeserialize(using = BooleanDeserializer.class)
@JsonProperty("Timestamp")
ZonedDateTime timestamp;
@CatalogExportField(columnName = "K", headerName = "catalog nae")
private Boolean mpAvailable;

And another class like this

public class BooleanDeserializer {
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {

but could not find any proper example.

this is also

    @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface CatalogExportField {

    String color() default "#56aaff";

    String columnName() default "";

    String headerName() default "";

    String displayName() default "";
}
mark
  • 727
  • 3
  • 14
  • 35

1 Answers1

1

You can use jackson, it deserealize you're booleans automatically, there are a lot of examples in StackOverflow:

Jackson renames primitive boolean field by removing 'is'

Fasterxml Jackson automatically converts non-boolean value to a boolean value

And you always can do your custom, of course:

https://hussainpithawala.wordpress.com/2011/05/11/overriding-default-serializationdeserialization-behaviour-of-jackson-json-serializer/

Community
  • 1
  • 1
developer_hatch
  • 15,898
  • 3
  • 42
  • 75