Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ It currently consists of

# Release Notes
BOAT is still under development and subject to change.

## 0.17.75
* Fixed duplicate serialization of the discriminator property in Jackson-based Java models by removing allowGetters = true from the @JsonIgnoreProperties annotation.

## 0.17.74
* Swift5: Removed deprecated initializer from model objects. The initializer is now internal and only accessible through the Builder pattern, preventing breaking code from deprecation warnings.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{{#-first}}
@JsonIgnoreProperties(
value = "{{{discriminator.propertyBaseName}}}", // ignore manually set {{{discriminator.propertyBaseName}}}, it will be automatically generated by Jackson during serialization
allowGetters = true, // allows the {{{discriminator.propertyBaseName}}} to be set during serialization
allowSetters = true // allows the {{{discriminator.propertyBaseName}}} to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "{{{discriminator.propertyBaseName}}}", visible = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.DynamicContainer.dynamicContainer;
import static org.junit.jupiter.api.DynamicTest.dynamicTest;

import com.backbase.oss.codegen.java.VerificationRunner.Verification;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.ArrayType;
import com.fasterxml.jackson.databind.type.TypeBindings;
Expand Down Expand Up @@ -260,32 +262,42 @@ private void verifyGeneratedClasses(File projectDir) throws Exception {

private void verifyReceivableRequestModelJsonConversion(ClassLoader classLoader) throws InterruptedException {
String testedModelClassName = buildReceivableRequestModelClassName();
String parentModelClassName = buildPaymentRequestModelClassName();
var objectMapper = new ObjectMapper();
Runnable verificationRunnable = () -> {
try {
Class<?> modelClass = classLoader.loadClass(testedModelClassName);
Class<?> parentClass = classLoader.loadClass(parentModelClassName);
Constructor<?> constructor = modelClass.getConstructor(String.class, String.class, String.class);
Object modelObject1 = constructor.newInstance("OK_status", "ref123", "EUR");
Object modelObject2 = constructor.newInstance("BAD_status", "ref456", "USD");

// Serialize using the parent (discriminated) type so that Jackson's
// is aware of full polymorphic context
TypeFactory tf = TypeFactory.defaultInstance();

// serialize and deserialize list
List<?> modelObjects = List.of(modelObject1, modelObject2);
String serializedObjects = objectMapper.writeValueAsString(modelObjects);
String serializedObjects = objectMapper.writerFor(
tf.constructCollectionType(List.class, parentClass)
).writeValueAsString(modelObjects);
Object[] deserializedModelObjects = objectMapper.readValue(
serializedObjects,
ArrayType.construct(
TypeFactory.defaultInstance().constructFromCanonical(modelClass.getName()),
tf.constructFromCanonical(parentClass.getName()),
TypeBindings.emptyBindings()
)
);
assertEquals(modelObjects.size(), deserializedModelObjects.length);
assertEquals(modelObject1.getClass(), deserializedModelObjects[0].getClass());

// serialize and deserialize single object
String serializedObject1 = objectMapper.writeValueAsString(modelObject1);
Object deserializedObject1 = objectMapper.readValue(serializedObject1, modelClass);
String serializedObject1 = objectMapper.writerFor(parentClass).writeValueAsString(modelObject1);
Object deserializedObject1 = objectMapper.readValue(serializedObject1, parentClass);
assertEquals(modelClass, deserializedObject1.getClass());

verifyJsonIgnoreAnnotation(modelClass);
verifyJsonIgnoreAnnotation(parentClass);
} catch (Exception e) {
throw new UnhandledException(e);
}
Expand All @@ -296,6 +308,15 @@ private void verifyReceivableRequestModelJsonConversion(ClassLoader classLoader)
);
}

private void verifyJsonIgnoreAnnotation(Class<?> modelClass) {
JsonIgnoreProperties ignoreAnnotation = modelClass.getAnnotation(JsonIgnoreProperties.class);

if (ignoreAnnotation != null) {
assertFalse(ignoreAnnotation.allowGetters(),
"Class " + modelClass.getName() + " should not have allowGetters=true in @JsonIgnoreProperties");
}
}

private void verifyMultiLineRequest(ClassLoader classLoader) throws InterruptedException {
String testedModelClassName = buildMultiLineRequestModelClassName();
Runnable verificationRunnable = () -> {
Expand All @@ -319,23 +340,28 @@ private void verifyMultiLineRequest(ClassLoader classLoader) throws InterruptedE
* Build proper class name for `ReceivableRequest`.
*/
private String buildReceivableRequestModelClassName() {
return buildModelClassName("ReceivableRequest");
}

/**
* Build proper class name for `PaymentRequest` (parent/discriminator base).
*/
private String buildPaymentRequestModelClassName() {
return buildModelClassName("PaymentRequest");
}

private String buildModelClassName(String baseName) {
var modelPackage = param.name.replace('-', '.') + ".model";
var classNameSuffix = org.apache.commons.lang3.StringUtils.capitalize(
param.name.indexOf('-') > -1
? CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, param.name)
: param.name
);
return modelPackage + ".ReceivableRequest" + classNameSuffix;
return modelPackage + "." + baseName + classNameSuffix;
}

private String buildMultiLineRequestModelClassName() {
var modelPackage = param.name.replace('-', '.') + ".model";
var classNameSuffix = org.apache.commons.lang3.StringUtils.capitalize(
param.name.indexOf('-') > -1
? CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, param.name)
: param.name
);
return modelPackage + ".MultiLinePaymentRequest" + classNameSuffix;
return buildModelClassName("MultiLinePaymentRequest");
}

private boolean findPattern(String filePattern, String linePattern) {
Expand Down