Skip to content

Commit 5decb71

Browse files
authored
Merge pull request #1254 from WebFuzzing/ind-schedule-task
handle unknown field in seeded tests
2 parents 931dbbd + 6aff6d8 commit 5decb71

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

client-java/controller/src/main/java/org/evomaster/client/java/controller/problem/rpc/schema/params/NamedTypedValue.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package org.evomaster.client.java.controller.problem.rpc.schema.params;
22

33
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.DeserializationFeature;
45
import com.fasterxml.jackson.databind.ObjectMapper;
56
import org.evomaster.client.java.controller.api.dto.problem.rpc.ParamDto;
67
import org.evomaster.client.java.controller.problem.rpc.schema.types.AccessibleSchema;
78
import org.evomaster.client.java.controller.problem.rpc.schema.types.PrimitiveOrWrapperType;
89
import org.evomaster.client.java.controller.problem.rpc.schema.types.TypeSchema;
10+
import org.evomaster.client.java.utils.SimpleLogger;
911

1012
import java.util.ArrayList;
1113
import java.util.List;
@@ -21,6 +23,9 @@ public abstract class NamedTypedValue<T extends TypeSchema, V> {
2123

2224
protected final static ObjectMapper objectMaper = new ObjectMapper();
2325

26+
protected final static ObjectMapper mapperAllowUnkownFields = new ObjectMapper()
27+
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
28+
2429
/**
2530
* name of the instance, eg param name
2631
*/
@@ -225,7 +230,27 @@ else if (PrimitiveOrWrapperType.isPrimitiveOrTypes(json.getClass())){
225230
}
226231

227232
public Object parseValueWithJson(String json) throws JsonProcessingException {
228-
return objectMaper.readValue(json, getType().getClazz());
233+
try{
234+
return objectMaper.readValue(json, getType().getClazz());
235+
}catch (JsonProcessingException e) {
236+
/*
237+
In the seeded tests of the industrial case study, there are cases where
238+
unrecognized fields appear in the JSON input, such as:
239+
{
240+
"setType": true // Note: there is no corresponding 'setType' field in the target class
241+
}
242+
243+
To handle such cases while still capturing the error message,
244+
attempt to parse the JSON again with a configuration that allows unknown fields.
245+
*/
246+
if (e.getMessage().contains("Unrecognized field")) {
247+
SimpleLogger.recordErrorMessage(
248+
String.format("Try once to fix issues in json: %s", e.getMessage()));
249+
return mapperAllowUnkownFields.readValue(json, getType().getClazz());
250+
}
251+
throw e;
252+
}
253+
229254
}
230255

231256
/**

e2e-tests/spring-rpc/spring-rpc-thrift/src/test/java/com/foo/rpc/examples/spring/fakemockobject/FakeMockObjectController.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,30 @@ public List<SeededRPCTestDto> seedRPCTests() {
181181
descriptiveInfo = "a scheduled task for invoking executeFlag";
182182
}}
183183
);
184+
}},
185+
new SeededRPCTestDto() {{
186+
testName = "test_7";
187+
rpcFunctions = Arrays.asList(
188+
new SeededRPCActionDto() {{
189+
interfaceName = FakeMockObjectService.Iface.class.getName();
190+
functionName = "getFooFromExternalService";
191+
inputParams = Arrays.asList("0");
192+
inputParamTypes = Arrays.asList(int.class.getName());
193+
mockRPCExternalServiceDtos = Arrays.asList(
194+
new MockRPCExternalServiceDto() {{
195+
appKey = "fake.app";
196+
interfaceFullName = "com.foo.rpc.examples.spring.fakemockobject.external.fake.api.GetApiData";
197+
functionName = "one";
198+
responses = Arrays.asList("{\"exName\":\"abc\",\"exId\":0,\"exInfo\":[\"2025-05-28\"],\"unknownField\":\"unknown\"}");
199+
responseTypes = Arrays.asList(
200+
"com.foo.rpc.examples.spring.fakemockobject.external.fake.api.ExApiDto"
201+
);
202+
}}
203+
);
204+
}}
205+
);
184206
}}
207+
185208
);
186209
}
187210

0 commit comments

Comments
 (0)