Skip to content

Commit

Permalink
bugfix: do not ignore json field names from annotations (#934)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlukas authored Sep 5, 2024
1 parent 106fed4 commit 1d96544
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
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;
}
}

0 comments on commit 1d96544

Please sign in to comment.