# devopsgym / testgen__fasterxml__jackson-databind-3851 - taskset: [devopsgym](https://harnessreport.com/tasks/devopsgym.md) - difficulty: hard - category: test-generation - language: - runnable from the site: no - agent timeout: 3000s ## Results by harness _none yet_ ## Instruction ``` The following text contains a user issue (in <issue/> brackets) posted at a repository. Further, you are provided with file contents of several files in the repository that contain relevant code (in <code> brackets). It may be necessary to use code from third party dependencies or files not contained in the attached documents however. Your task is to identify the issue and implement a test case that verifies a proposed solution to this issue. More details at the end of this text. <issue> **Describe the bug** When Enum has two factory methods, one with `JsonCreator.Mode.DELEGATING` and the other with `JsonCreator.Mode.PROPERTIES`, only the latter works. Deserialization that is supposed to target the DELEGATING one fails with `com.fasterxml.jackson.databind.exc.MismatchedInputException`. Note that the same setup for a POJO works just fine. **Version information** 2.13.3 **To Reproduce** ```java class TestCases { @Test void testClass() throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); Assertions.assertEquals(new AClass("someName"), objectMapper.readValue("{ \"name\": \"someName\" }", AClass.class)); Assertions.assertEquals(new AClass("someName"), objectMapper.readValue("\"someName\"", AClass.class)); } @Test void testEnum() throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); Assertions.assertEquals(AEnum.A, objectMapper.readValue("{ \"type\": \"AType\" }", AEnum.class)); Assertions.assertEquals(AEnum.A, objectMapper.readValue("\"AType\"", AEnum.class)); // this line fails } } class AClass { private final String name; AClass(String name) { this.name = name; } public String getName() { return name; } @JsonCreator(mode = JsonCreator.Mode.DELEGATING) public static AClass fromString(String name) { return new AClass(name); } @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public static AClass create(@JsonProperty("name") String name) { return new AClass(name); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; AClass aClass = (AClass) o; return Objects.equals(name, aClass.name); } @Override public int hashCode() { return Objects.hash(name); } } @JsonFormat(shape = JsonFormat.Shape.OBJECT) enum AEnum { A("AType"), B("BType"); private final String type; AEnum(String type) { this.type = type; } public String getType() { return type; } @JsonCreator(mode = JsonCreator.Mode.DELEGATING) public static AEnum fromString(String type) { return Arrays.stream(values()) .filter(aEnum -> aEnum.type.equals(type)) .findFirst() .orElseThrow(); } @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) public static AEnum create(@JsonProperty("type") String type) { return fromString(type); } } ``` The `testClass` passes, but `testEnum` fails with ``` com.fasterxml.jackson.databind.exc.MismatchedInputException: Input mismatch reading Enum `AEnum`: properties-based `@JsonCreator` ([method AEnum#fromString(java.lang.String)]) expects JSON Object (JsonToken.START_OBJECT), got JsonToken.VALUE_STRING ``` Also, you can remove the PROPERTIES factory method, and the DELEGATING method would work. </issue> Please generate test cases that check whether an implemented solution resolves the issue of the user (at the top, within <issue/> brackets). You may apply changes to several files. Apply as much reasoning as you please and see necessary. Make sure to implement only test cases and don't try to fix the issue itself. You are not allowed to read git history. ``` --- Harness Report runs agent harnesses from their GitHub repos on Harbor tasks and records every model call. Every page is also `.md` and `.json`; index: https://harnessreport.com/llms.txt · MCP: https://harnessreport.com/mcp