Hi, 

Here's a question I've posted on SO - crossposting here in hope of getting 
some domain-expertise.


I have a 3rd party Lombok builder POJO, one that I cannot modify, that I 
want to serialize using jackson. Notably it does *not* have a 
NoArgsConstructor.

@Data@Builderpublic class ExternalClass {
   private String name;
   private String data; 
   // etc.} 


On the surface this would appear to be simple, but it is incredibly 
frustrating in practice as each possible option seems to be counteracted by 
a different complication. In essence, I'm having trouble getting an 
*external* Lombok *builder* to work with a jackson *mixin*.


Lombok produces fluent setters of the style .name(String name) while 
Jackson's built-in builder deserializer expects .withName(String name). 
Lombok documentation, and recipes elsewhere such as here 
<https://stackoverflow.com/questions/4982340/jackson-builder-pattern> suggest 
using @JsonDeserialize(builder=ExternalClass.ExternalClassBuilder.class) in 
conjunction with @JsonPOJOBuilder(withPrefix="") on a predeclared inner 
stub builder. But this is not possible because the Lombok class is in an 
external library.


Applying these annotations to a mixin has no effect.


@JsonDeserialize(ExternalClass.ExternalClassBuilder.class)public abstract class 
ExternalClassMixin {
   @JsonPOJOBuilder(withPrefix="")
   public static ExternalClassBuilder {
   }} 


The only approach I've found that works is to leverage the package-access 
AllArgsConstructor created by @Builder and populate the mixin with the 
following constructor

public abstract class ExternalClassMixin {
   @JsonCreator public ExternalClassMixin(
      @JsonProperty("name") String name,
      @JsonProperty("data") String data,
      // etc.
  ) {} } 


This is obviously not desirable as it requires iterating and hard-coding 
every class property explicitly, making the mixin fragile to any change in 
the external POJO.

My question is - is there a robust, maintainable way to serialize this 
external builder class using Jackson without modifying it, using either a 
mixin or maybe a full blown deserializer?

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to