Skip to content

Commit fa37ddd

Browse files
committed
Merge branch 'master' into vulnerability-analyser
2 parents 67048e6 + a82573d commit fa37ddd

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
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
/**

core/src/main/kotlin/org/evomaster/core/problem/rest/builder/CreateResourceUtils.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,22 @@ object CreateResourceUtils {
5050
POST /x
5151
POST /x/{id}/y
5252
GET /x/{id}/y
53-
not going to save the position of last POST, as same as target
53+
not need to save the position of last POST, as same as target
5454
5555
however, might also be in the case of:
5656
PUT /x/{id}
5757
GET /x/{id}
5858
*/
59-
before.saveCreatedResourceLocation = false
59+
/*
60+
removing the flag here was a mistake.
61+
even if after is not using the resource path, between "before" and "after"
62+
there could be other calls that need it, eg:
63+
64+
PUT /x/{a}
65+
PUT /x/{a}/y/{b}
66+
DELETE /x/{a}
67+
*/
68+
//before.saveCreatedResourceLocation = false
6069

6170
// the target (eg GET) needs to use the location of first POST, or more correctly
6271
// the same location used for the last POST (in case there is a deeper chain)

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)