-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve lenient mode documentation (#2122)
- Loading branch information
1 parent
3f1d4fb
commit cbc0af8
Showing
6 changed files
with
185 additions
and
36 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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.google.gson; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
|
||
import com.google.gson.stream.JsonReader; | ||
import com.google.gson.stream.JsonWriter; | ||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import org.junit.Test; | ||
|
||
public class TypeAdapterTest { | ||
@Test | ||
public void testNullSafe() throws IOException { | ||
TypeAdapter<String> adapter = new TypeAdapter<String>() { | ||
@Override public void write(JsonWriter out, String value) { | ||
throw new AssertionError("unexpected call"); | ||
} | ||
|
||
@Override public String read(JsonReader in) { | ||
throw new AssertionError("unexpected call"); | ||
} | ||
}.nullSafe(); | ||
|
||
assertEquals("null", adapter.toJson(null)); | ||
assertNull(adapter.fromJson("null")); | ||
} | ||
|
||
private static final TypeAdapter<String> adapter = new TypeAdapter<String>() { | ||
@Override public void write(JsonWriter out, String value) throws IOException { | ||
out.value(value); | ||
} | ||
|
||
@Override public String read(JsonReader in) throws IOException { | ||
return in.nextString(); | ||
} | ||
}; | ||
|
||
// Note: This test just verifies the current behavior; it is a bit questionable | ||
// whether that behavior is actually desired | ||
@Test | ||
public void testFromJson_Reader_TrailingData() throws IOException { | ||
assertEquals("a", adapter.fromJson(new StringReader("\"a\"1"))); | ||
} | ||
|
||
// Note: This test just verifies the current behavior; it is a bit questionable | ||
// whether that behavior is actually desired | ||
@Test | ||
public void testFromJson_String_TrailingData() throws IOException { | ||
assertEquals("a", adapter.fromJson("\"a\"1")); | ||
} | ||
} |