You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to write a custom rule factor where it would wrap the type into a field wrapper. This field wrapper will be used to distinguish the serialization of the following object
User user1 = new User().withName("Adam");
String user1Serialized = OBJECT_MAPPER.writeToString(user1); // -> { "name": "Adam" }
User user2 = new User().withName("Adam").withEmail(null);
String user2Serialized = OBJECT_MAPPER.writeToString(user2); // -> { "name": "Adam", "email": null }
The implementation of field wrapper is as follow
@JsonSerialize(using = FieldWrapperSerializer.class)
public class FieldWrapper<T> {
private T value;
private boolean explicitlySet = false;
public FieldWrapper() {}
public FieldWrapper(T value) {
this.value = value;
this.explicitlySet = true;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
this.explicitlySet = true;
}
public boolean isExplicitlySet() {
return explicitlySet;
}
}
public class FieldWrapperSerializer extends JsonSerializer<FieldWrapper<?>> {
@Override
public void serialize(FieldWrapper<?> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
if (value.isExplicitlySet()) {
gen.writeObject(value.getValue());
}
}
}
I also implement why own custom type rule and rule factor
public class NullTypeRule extends TypeRule {
public NullTypeRule(RuleFactory ruleFactory) {
super(ruleFactory);
}
@Override
public JType apply(String nodeName, JsonNode node, JsonNode parent, JClassContainer jClassContainer, Schema schema) {
JType fieldType = super.apply(nodeName, node, parent, jClassContainer, schema);
return fieldType.owner().ref(FieldWrapper.class).narrow(fieldType);
}
}
public class NullRuleFactory extends RuleFactory {
@Override
public Rule<JClassContainer, JType> getTypeRule() {
return new NullTypeRule(this);
}
}
java.lang.ClassNotFoundException indicates that the cause for issue is that indicated class is not accessible during jsonschema2pojo plugin execution phase.
One could:
publish artifact with com.myproject.NullRuleFactory + related classes and add it to jsonschema2pojo plugin dependencies
I am trying to write a custom rule factor where it would wrap the type into a field wrapper. This field wrapper will be used to distinguish the serialization of the following object
The implementation of field wrapper is as follow
I also implement why own custom type rule and rule factor
In my build.gradle
I got the following error
Caused by: java.lang.ClassNotFoundException: com.myproject.NullRuleFactory
. Can I get help on this? Thank you.The text was updated successfully, but these errors were encountered: