-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
d34c221
commit 0f590b9
Showing
9 changed files
with
104 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
android-record/src/test/java/com/fasterxml/jackson/module/androidrecord/BaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
package com.fasterxml.jackson.module.androidrecord; | ||
|
||
import java.util.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.android.tools.r8.RecordTag; | ||
|
||
import com.fasterxml.jackson.annotation.JacksonInject; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; | ||
import com.fasterxml.jackson.databind.json.JsonMapper; | ||
import com.fasterxml.jackson.databind.type.TypeFactory; | ||
import com.fasterxml.jackson.databind.util.Converter; | ||
import org.junit.Assert; | ||
|
||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class RecordBasicsTest extends BaseMapTest { | ||
public class RecordBasicsTest extends BaseMapTest | ||
{ | ||
static final class EmptyRecord extends RecordTag { | ||
@Override | ||
public boolean equals(Object o) { | ||
|
@@ -327,13 +330,15 @@ public String toString() { | |
/********************************************************************** | ||
*/ | ||
|
||
@Test | ||
public void testClassUtil() { | ||
assertFalse(AndroidRecordModule.isDesugaredRecordClass(getClass())); | ||
assertTrue(AndroidRecordModule.isDesugaredRecordClass(SimpleRecord.class)); | ||
assertTrue(AndroidRecordModule.isDesugaredRecordClass(RecordOfRecord.class)); | ||
assertTrue(AndroidRecordModule.isDesugaredRecordClass(RecordWithRename.class)); | ||
} | ||
|
||
@Test | ||
public void testRecordJavaType() { | ||
assertFalse(AndroidRecordModule.isDesugaredRecordClass(MAPPER.constructType(getClass()).getRawClass())); | ||
assertTrue(AndroidRecordModule.isDesugaredRecordClass(MAPPER.constructType(SimpleRecord.class).getRawClass())); | ||
|
@@ -347,26 +352,31 @@ public void testRecordJavaType() { | |
/********************************************************************** | ||
*/ | ||
|
||
@Test | ||
public void testSerializeSimpleRecord() throws Exception { | ||
String json = MAPPER.writeValueAsString(new SimpleRecord(123, "Bob")); | ||
final Object EXP = map("id", Integer.valueOf(123), "name", "Bob"); | ||
assertEquals(EXP, MAPPER.readValue(json, Object.class)); | ||
} | ||
|
||
@Test | ||
public void testDeserializeSimpleRecord() throws Exception { | ||
assertEquals(new SimpleRecord(123, "Bob"), | ||
MAPPER.readValue("{\"id\":123,\"name\":\"Bob\"}", SimpleRecord.class)); | ||
} | ||
|
||
@Test | ||
public void testSerializeEmptyRecord() throws Exception { | ||
assertEquals("{}", MAPPER.writeValueAsString(new EmptyRecord())); | ||
} | ||
|
||
@Test | ||
public void testDeserializeEmptyRecord() throws Exception { | ||
assertEquals(new EmptyRecord(), | ||
MAPPER.readValue("{}", EmptyRecord.class)); | ||
} | ||
|
||
@Test | ||
public void testSerializeRecordOfRecord() throws Exception { | ||
RecordOfRecord record = new RecordOfRecord(new SimpleRecord(123, "Bob")); | ||
String json = MAPPER.writeValueAsString(record); | ||
|
@@ -375,6 +385,7 @@ public void testSerializeRecordOfRecord() throws Exception { | |
assertEquals(EXP, MAPPER.readValue(json, Object.class)); | ||
} | ||
|
||
@Test | ||
public void testDeserializeRecordOfRecord() throws Exception { | ||
assertEquals(new RecordOfRecord(new SimpleRecord(123, "Bob")), | ||
MAPPER.readValue("{\"record\":{\"id\":123,\"name\":\"Bob\"}}", | ||
|
@@ -387,6 +398,7 @@ public void testDeserializeRecordOfRecord() throws Exception { | |
/********************************************************************** | ||
*/ | ||
|
||
@Test | ||
public void testSerializeSimpleRecord_DisableAnnotationIntrospector() throws Exception { | ||
SimpleRecord record = new SimpleRecord(123, "Bob"); | ||
|
||
|
@@ -398,12 +410,14 @@ public void testSerializeSimpleRecord_DisableAnnotationIntrospector() throws Exc | |
assertEquals("{\"id\":123,\"name\":\"Bob\"}", json); | ||
} | ||
|
||
@Test | ||
public void testDeserializeSimpleRecord_DisableAnnotationIntrospector() throws Exception { | ||
JsonMapper mapper = JsonMapper.builder().addModule(new AndroidRecordModule()) | ||
.configure(MapperFeature.USE_ANNOTATIONS, false) | ||
.build(); | ||
|
||
Assert.assertThrows(InvalidDefinitionException.class, () -> mapper.readValue("{\"id\":123,\"name\":\"Bob\"}", SimpleRecord.class)); | ||
assertThrows(InvalidDefinitionException.class, | ||
() -> mapper.readValue("{\"id\":123,\"name\":\"Bob\"}", SimpleRecord.class)); | ||
} | ||
|
||
/* | ||
|
@@ -412,18 +426,21 @@ public void testDeserializeSimpleRecord_DisableAnnotationIntrospector() throws E | |
/********************************************************************** | ||
*/ | ||
|
||
@Test | ||
public void testSerializeJsonRename() throws Exception { | ||
String json = MAPPER.writeValueAsString(new RecordWithRename(123, "Bob")); | ||
final Object EXP = map("id", Integer.valueOf(123), "rename", "Bob"); | ||
assertEquals(EXP, MAPPER.readValue(json, Object.class)); | ||
} | ||
|
||
@Test | ||
public void testDeserializeJsonRename() throws Exception { | ||
RecordWithRename value = MAPPER.readValue("{\"id\":123,\"rename\":\"Bob\"}", | ||
RecordWithRename.class); | ||
assertEquals(new RecordWithRename(123, "Bob"), value); | ||
} | ||
|
||
@Test | ||
public void testDeserializeConstructorInjectRecord() throws Exception { | ||
MAPPER.setInjectableValues(new InjectableValues.Std().addValue(String.class, "Bob")); | ||
|
||
|
@@ -438,6 +455,7 @@ public void testDeserializeConstructorInjectRecord() throws Exception { | |
*/ | ||
|
||
// [databind#2992] | ||
@Test | ||
public void testNamingStrategy() throws Exception { | ||
SnakeRecord input = new SnakeRecord("123", "value"); | ||
|
||
|
@@ -454,25 +472,29 @@ public void testNamingStrategy() throws Exception { | |
/********************************************************************** | ||
*/ | ||
|
||
@Test | ||
public void testSerialize_SingleWriteOnlyParameter() throws Exception { | ||
String json = MAPPER.writeValueAsString(new RecordSingleWriteOnly(123)); | ||
|
||
assertEquals("{}", json); | ||
} | ||
|
||
// [databind#3897] | ||
@Test | ||
public void testDeserialize_SingleWriteOnlyParameter() throws Exception { | ||
RecordSingleWriteOnly value = MAPPER.readValue("{\"id\":123}", RecordSingleWriteOnly.class); | ||
|
||
assertEquals(new RecordSingleWriteOnly(123), value); | ||
} | ||
|
||
@Test | ||
public void testSerialize_SomeWriteOnlyParameter() throws Exception { | ||
String json = MAPPER.writeValueAsString(new RecordSomeWriteOnly(123, "Bob", "[email protected]")); | ||
|
||
assertEquals("{\"email\":\"[email protected]\"}", json); | ||
} | ||
|
||
@Test | ||
public void testDeserialize_SomeWriteOnlyParameter() throws Exception { | ||
RecordSomeWriteOnly value = MAPPER.readValue( | ||
"{\"id\":123,\"name\":\"Bob\",\"email\":\"[email protected]\"}", | ||
|
@@ -481,12 +503,14 @@ public void testDeserialize_SomeWriteOnlyParameter() throws Exception { | |
assertEquals(new RecordSomeWriteOnly(123, "Bob", "[email protected]"), value); | ||
} | ||
|
||
@Test | ||
public void testSerialize_AllWriteOnlyParameter() throws Exception { | ||
String json = MAPPER.writeValueAsString(new RecordAllWriteOnly(123, "Bob", "[email protected]")); | ||
|
||
assertEquals("{}", json); | ||
} | ||
|
||
@Test | ||
public void testDeserialize_AllWriteOnlyParameter() throws Exception { | ||
RecordAllWriteOnly value = MAPPER.readValue( | ||
"{\"id\":123,\"name\":\"Bob\",\"email\":\"[email protected]\"}", | ||
|
@@ -502,6 +526,7 @@ public void testDeserialize_AllWriteOnlyParameter() throws Exception { | |
*/ | ||
|
||
// Fails: converter not applied | ||
@Test | ||
public void testDeserializeJsonDeserializeRecord() throws Exception { | ||
RecordWithJsonDeserialize value = MAPPER.readValue("{\"id\":123,\"name\":\" Bob \"}", | ||
RecordWithJsonDeserialize.class); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.