Skip to content

Move 4961 test out of tofix #4965

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

Merged
merged 1 commit into from
Feb 9, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.databind.tofix;
package com.fasterxml.jackson.databind.struct;

import java.util.Map;
import java.util.TreeMap;
Expand All @@ -8,7 +8,6 @@
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -21,7 +20,6 @@ static class WrapperForAnyGetter {
public BeanWithAnyGetter value;
}

@JsonPropertyOrder({ "firstProperty", "secondProperties", "anyProperty", "forthProperty" })
Copy link
Member

@cowtowncoder cowtowncoder Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not have been removed because ordering for 3.0 will differ from 2.x (when properties added in alphabetic order by default). Will add back annotation, except for "anyProperty"

@JsonFormat(shape = JsonFormat.Shape.ARRAY)
static class BeanWithAnyGetter {
public String firstProperty = "first";
Expand All @@ -38,47 +36,22 @@ public Map<String, String> getAnyProperty() {

final ObjectMapper MAPPER = newJsonMapper();

@JacksonTestFailureExpected
@Test
public void testSerializeArrayWithAnyGetterWithWrapper() throws Exception {
WrapperForAnyGetter wrapper = new WrapperForAnyGetter();
wrapper.value = new BeanWithAnyGetter();

String json = MAPPER.writeValueAsString(wrapper);

// In 2.19, Fails Actual
// : {"value":{"firstProperty":"first","secondProperties":"second","forthProperty":"forth","third_A":"third_A","third_B":"third_B"}}
// Getting better, after #4775 in 2.19, fails Actual
// : {"value":["first","second",{"third_A":"third_A","third_B":"third_B"},"forth"]}
assertEquals(a2q("{'value':" +
"[" +
"'first'," +
"'second'," +
"'forth'," +
"'third_A'," +
"'third_B'" +
"]" +
"}"), json);
assertEquals(a2q("{\"value\":[\"first\",\"second\",\"forth\",{\"third_A\":\"third_A\",\"third_B\":\"third_B\"}]}"), json);
}

@JacksonTestFailureExpected
@Test
public void testSerializeArrayWithAnyGetterAsRoot() throws Exception {
BeanWithAnyGetter bean = new BeanWithAnyGetter();

String json = MAPPER.writeValueAsString(bean);

// In 2.19, Fails Actual
// : {"firstProperty":"first","secondProperties":"second","forthProperty":"forth","third_A":"third_A","third_B":"third_B"}

// Getting better, after #4775 in 2.19, fails Actual
// : ["first","second",{"third_A":"third_A","third_B":"third_B"},"forth"]
assertEquals(a2q("[" +
"'first'," +
"'second'," +
"'forth'," +
"'third_A'," +
"'third_B'" +
"]"), json);
assertEquals(a2q("[\"first\",\"second\",\"forth\",{\"third_A\":\"third_A\",\"third_B\":\"third_B\"}]"), json);
}
}