Skip to content

Commit

Permalink
Merge branch 'master' into tatu/3.0/4891-rm-moditect-add-module-info
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 11, 2025
2 parents 6b4ec48 + 87c6b51 commit d5d18ae
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package tools.jackson.databind.deser.filter;

import java.beans.ConstructorProperties;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import tools.jackson.databind.ObjectMapper;

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

import static tools.jackson.databind.testutil.DatabindTestUtil.newJsonMapper;

public class ReadOnlyDeser95Test
{
// [databind#95]
@JsonIgnoreProperties(value={ "computed" }, allowGetters=true)
static class ReadOnly95Bean
{
public int value = 3;

public int getComputed() { return 32; }
}

static class Person {
public String name;
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private TestEnum testEnum = TestEnum.DEFAULT;

Person() { }

public Person(TestEnum testEnum, String name) {
this.testEnum = testEnum;
this.name = name;
}

public TestEnum getTestEnum() {
return testEnum;
}

public void setTestEnum(TestEnum testEnum) {
this.testEnum = testEnum;
}
}

enum TestEnum{
DEFAULT, TEST;
}

/*
/**********************************************************
/* Test methods
/**********************************************************
*/

private final ObjectMapper MAPPER = newJsonMapper();

// [databind#95]
@Test
public void testReadOnlyProps95() throws Exception
{
ObjectMapper m = new ObjectMapper();
String json = m.writeValueAsString(new ReadOnly95Bean());
if (json.indexOf("computed") < 0) {
fail("Should have property 'computed', didn't: "+json);
}
ReadOnly95Bean bean = m.readValue(json, ReadOnly95Bean.class);
assertNotNull(bean);
}

@Test
public void testDeserializeOneField() throws Exception {
Person person = MAPPER.readValue("{\"testEnum\":\"\"}", Person.class);
assertEquals(TestEnum.DEFAULT, person.getTestEnum());
assertNull(person.name);
}

@Test
public void testDeserializeTwoFields() throws Exception {
Person person = MAPPER.readValue("{\"testEnum\":\"\",\"name\":\"changyong\"}",
Person.class);
assertEquals(TestEnum.DEFAULT, person.getTestEnum());
assertEquals("changyong", person.name);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package tools.jackson.databind.deser.filter;
package tools.jackson.databind.ext.desktop;

import java.beans.ConstructorProperties;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import tools.jackson.databind.ObjectMapper;
Expand All @@ -13,17 +12,8 @@

import static tools.jackson.databind.testutil.DatabindTestUtil.newJsonMapper;

public class ReadOnlyDeser1890Test
public class ReadOnlyDeserWithConstructorProperties1890Test
{
// [databind#95]
@JsonIgnoreProperties(value={ "computed" }, allowGetters=true)
static class ReadOnly95Bean
{
public int value = 3;

public int getComputed() { return 32; }
}

// [databind#1890]
static class PersonAnnotations {
public String name;
Expand Down Expand Up @@ -80,19 +70,6 @@ enum TestEnum{

private final ObjectMapper MAPPER = newJsonMapper();

// [databind#95]
@Test
public void testReadOnlyProps95() throws Exception
{
ObjectMapper m = new ObjectMapper();
String json = m.writeValueAsString(new ReadOnly95Bean());
if (json.indexOf("computed") < 0) {
fail("Should have property 'computed', didn't: "+json);
}
ReadOnly95Bean bean = m.readValue(json, ReadOnly95Bean.class);
assertNotNull(bean);
}

// [databind#1890]
@Test
public void testDeserializeAnnotationsOneField() throws Exception {
Expand Down

0 comments on commit d5d18ae

Please sign in to comment.