В поле есть @JsonValue, и я тоже попробовал
Код: Выделить всё
mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)
Спасибо.
Фрагменты кода:
Код вызова Mapper:
Код: Выделить всё
CDRequest CDRequest = new CDRequest();
CDIdentifier CDIdentifier = new CDIdentifier();
CDIdentifier.setInputType(InputTypeEnum.LEGACY);
CDRequest.setInputIdentifier(CDIdentifier);
String c = mapper.writeValueAsString(CDRequest);
Код: Выделить всё
public class CDRequest {
public static final String JSON_PROPERTY_INPUT_IDENTIFIER = "inputIdentifier";
private CDIdentifier inputIdentifier;
public CDRequest inputIdentifier(CDIdentifier inputIdentifier) {
this.inputIdentifier = inputIdentifier;
return this;
}
@jakarta.annotation.Nullable
@JsonProperty(JSON_PROPERTY_INPUT_IDENTIFIER)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public CDIdentifier getInputIdentifier() {
return inputIdentifier;
}
@JsonProperty(JSON_PROPERTY_INPUT_IDENTIFIER)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setInputIdentifier(CDIdentifier inputIdentifier) {
this.inputIdentifier = inputIdentifier;
}
@JsonIgnoreProperties(
value = "inputType", // ignore manually set inputType, it will
be automatically generated by Jackson during serialization
allowSetters = true // allows the inputType to be set during
deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include =
JsonTypeInfo.As.PROPERTY, property = "inputType", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = CR.class, name = "CUSTOMER_ID"),
@JsonSubTypes.Type(value = CN.class, name = "CUSTOMER_NUMBER"),
@JsonSubTypes.Type(value = LCR.class, name = "LEGACY"),
@JsonSubTypes.Type(value = CR.class, name = "CR"),
@JsonSubTypes.Type(value = CN.class, name = "CN"),
@JsonSubTypes.Type(value = LCR.class, name = "LCR"),
})
}
Код: Выделить всё
public class CDIdentifier {
/**
* Gets or Sets inputType
*/
public enum InputTypeEnum {
LEGACY("LEGACY");
private String value;
InputTypeEnum(String value) {
this.value = value;
}
@JsonValue
public String getValue() {
return value;
}
@Override
public String toString() {
return String.valueOf(value);
}
@JsonCreator
public static InputTypeEnum fromValue(String value) {
for (InputTypeEnum b : InputTypeEnum.values()) {
if (b.value.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}
}
public static final String JSON_PROPERTY_INPUT_TYPE = "inputType";
protected InputTypeEnum inputType;
Подробнее здесь: https://stackoverflow.com/questions/791 ... d-of-value