Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: do not ignore json field names from annotations #934

Merged
merged 1 commit into from
Sep 5, 2024
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
5 changes: 5 additions & 0 deletions spring-boot-starter-camunda/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<artifactId>jackson-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.camunda.spring</groupId>
<artifactId>spring-client-zeebe</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.camunda.zeebe.spring.client.properties;

import static io.camunda.zeebe.spring.client.configuration.PropertyUtil.*;
import static io.camunda.zeebe.spring.client.properties.ZeebeClientConfigurationProperties.*;
import static java.util.Optional.*;
import static org.apache.commons.lang3.StringUtils.*;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.camunda.zeebe.client.api.response.ActivatedJob;
import io.camunda.zeebe.spring.client.annotation.Variable;
import io.camunda.zeebe.spring.client.annotation.VariablesAsType;
Expand All @@ -16,6 +16,7 @@
import io.camunda.zeebe.spring.client.bean.MethodInfo;
import io.camunda.zeebe.spring.client.bean.ParameterInfo;
import io.camunda.zeebe.spring.client.properties.common.ZeebeClientProperties;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -104,10 +105,17 @@ private List<String> readVariablesAsTypeParameters(MethodInfo methodInfo) {
parameters.forEach(
pi ->
ReflectionUtils.doWithFields(
pi.getParameterInfo().getType(), f -> result.add(f.getName())));
pi.getParameterInfo().getType(), f -> result.add(extractParameterName(f))));
return result;
}

private String extractParameterName(Field field) {
if (field.isAnnotationPresent(JsonProperty.class)) {
return field.getAnnotation(JsonProperty.class).value();
}
return field.getName();
}

private void applyOverrides(ZeebeWorkerValue zeebeWorker) {
final Map<String, ZeebeWorkerValue> workerConfigurationMap =
getOrLegacyOrDefault(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.assertj.core.api.Assertions.*;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.camunda.zeebe.client.api.response.ActivatedJob;
import io.camunda.zeebe.spring.client.annotation.JobWorker;
import io.camunda.zeebe.spring.client.annotation.Variable;
Expand Down Expand Up @@ -47,6 +48,9 @@ private static CamundaClientProperties properties() {
@JobWorker
void sampleWorker(@Variable String var1, @VariablesAsType ComplexProcessVariable var2) {}

@JobWorker
void sampleWorkerWithJsonProperty(@VariablesAsType PropertyAnnotatedClass var2) {}

@JobWorker
void activatedJobWorker(@Variable String var1, ActivatedJob activatedJob) {}

Expand Down Expand Up @@ -360,6 +364,19 @@ void shouldApplyWorkerOverridesOverGlobalOverrides() {
assertThat(zeebeWorkerValue.getEnabled()).isFalse();
}

@Test
void shouldApplyPropertyAnnotationOnVariableFiltering() {
// given
PropertyBasedZeebeWorkerValueCustomizer customizer =
new PropertyBasedZeebeWorkerValueCustomizer(legacyProperties(), properties());
ZeebeWorkerValue zeebeWorkerValue = new ZeebeWorkerValue();
zeebeWorkerValue.setMethodInfo(methodInfo(this, "testBean", "sampleWorkerWithJsonProperty"));
// when
customizer.customize(zeebeWorkerValue);
// then
assertThat(zeebeWorkerValue.getFetchVariables()).containsExactly("weird_name");
}

private static class ComplexProcessVariable {
private String var3;
private String var4;
Expand All @@ -380,4 +397,9 @@ public void setVar4(String var4) {
this.var4 = var4;
}
}

private static class PropertyAnnotatedClass {
@JsonProperty("weird_name")
private String value;
}
}