Skip to content

Commit

Permalink
Merge branch '2.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 17, 2024
2 parents 4728b4a + 552a543 commit f406086
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 33 deletions.
10 changes: 5 additions & 5 deletions jr-objects/src/test/java/tools/jackson/jr/ob/ReadSimpleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ static class DateWrapper {
*/

public void testByteArray() throws Exception {
byte[] result = JSON.std.beanFrom(byte[].class, quote("YWJj"));
byte[] result = JSON.std.beanFrom(byte[].class, q("YWJj"));
assertEquals("abc", new String(result, "UTF-8"));
}

public void testCharArray() throws Exception {
char[] result = JSON.std.beanFrom(char[].class, quote("abc"));
char[] result = JSON.std.beanFrom(char[].class, q("abc"));
assertEquals("abc", new String(result));
}

Expand Down Expand Up @@ -175,7 +175,7 @@ public void testBooleanFail() throws Exception {

public void testMiscScalars() throws Exception {
assertEquals(new Date(123456L), JSON.std.beanFrom(Date.class,"123456"));
assertEquals(Object.class, JSON.std.beanFrom(Class.class, quote(Object.class.getName())));
assertEquals(Object.class, JSON.std.beanFrom(Class.class, q(Object.class.getName())));
}

public void testMiscScalarFail() throws Exception {
Expand Down Expand Up @@ -265,7 +265,7 @@ public void testSimpleEnums() throws Exception
assertEquals(ABC.B, abc);

// then from name
abc = JSON.std.beanFrom(ABC.class, quote("C"));
abc = JSON.std.beanFrom(ABC.class, q("C"));
assertEquals(ABC.C, abc);

// `null`s ok too
Expand Down Expand Up @@ -304,7 +304,7 @@ public void testTreeReadWithoutCodec() throws Exception
}

try {
JSON.std.beanFrom(TreeNode.class, quote("abc"));
JSON.std.beanFrom(TreeNode.class, q("abc"));
fail("Should not pass");
} catch (JSONObjectException e) {
verifyException(e, "No `TreeCodec` specified");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static class FromLong2 {

public void testStringCtor() throws Exception
{
FromString output = JSON.std.beanFrom(FromString.class, quote("abc"));
FromString output = JSON.std.beanFrom(FromString.class, q("abc"));
assertNotNull(output);
assertEquals("abc", output.value);
}
Expand Down
7 changes: 1 addition & 6 deletions jr-objects/src/test/java/tools/jackson/jr/ob/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,14 @@ protected JsonParser parserFor(JSON json, String source) {
return json.tokenStreamFactory().createParser(ObjectReadContext.empty(), source.toCharArray());
}

protected String quote(String str) {
protected String q(String str) {
return "\"" + str + "\"";
}

protected String a2q(String json) {
return json.replace('\'', '"');
}

@Deprecated
protected String aposToQuotes(String json) {
return a2q(json);
}

protected JSON jsonWithModifier(final ReaderWriterModifier modifier) {
return JSON.builder().register(new JacksonJrExtension() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ public void testNest() throws Exception
public void testKnownSimpleTypes() throws Exception
{
final String URL_STR = "http://fasterxml.com";
assertEquals(quote("http:\\/\\/fasterxml.com"),
assertEquals(q("http:\\/\\/fasterxml.com"),
JSON.std.asString(new URI(URL_STR)));
final String PATH = "/foo/bar.txt";
assertEquals(quote("\\/foo\\/bar.txt"),
assertEquals(q("\\/foo\\/bar.txt"),
JSON.std.asString(new File(PATH)));

assertEquals(quote("B"), JSON.std.asString(ABC.B));
assertEquals(q("B"), JSON.std.asString(ABC.B));
assertEquals("1", JSON.std.with(Feature.WRITE_ENUMS_USING_INDEX).asString(ABC.B));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,21 @@ public void testCustomEnumReader() throws Exception
{
// First: without handler, will fail to map
try {
JSON.std.beanFrom(ABC.class, quote("n/a"));
JSON.std.beanFrom(ABC.class, q("n/a"));
fail("Should not pass");
} catch (JSONObjectException e) {
verifyException(e, "Failed to find Enum of type");
}

// then with custom, should be fine
JSON json = jsonWithProvider(new CustomReaders(0));
ABC v = json.beanFrom(ABC.class, quote("n/a"));
ABC v = json.beanFrom(ABC.class, q("n/a"));
assertEquals(ABC.DEF, v);

// but if we remove, again error
JSON json2 = jsonWithProvider((ReaderWriterProvider) null);
try {
json2.beanFrom(ABC.class, quote("n/a"));
json2.beanFrom(ABC.class, q("n/a"));
fail("Should not pass");
} catch (JSONObjectException e) {
verifyException(e, "Failed to find Enum of type");
Expand All @@ -248,31 +248,31 @@ public void testCustomEnumReader() throws Exception
public void testCustomStringReader() throws Exception
{
String allCaps = jsonWithProvider(new CapStringReaderProvider())
.beanFrom(String.class, quote("Some text"));
.beanFrom(String.class, q("Some text"));
assertEquals("SOME TEXT", allCaps);
}

public void testChainedStringReaders() throws Exception {
String result = jsonWithProviders(new CapStringReaderProvider(),
new OverrideStringReaderProvider("foo"))
.beanFrom(String.class, quote("Some text"));
.beanFrom(String.class, q("Some text"));
assertEquals("SOME TEXT", result);

result = jsonWithProviders(new NoOpProvider(), new OverrideStringReaderProvider("foo"))
.beanFrom(String.class, quote("Some text"));
.beanFrom(String.class, q("Some text"));
assertEquals("foo", result);

// and ok not to have anything, too
result = jsonWithProviders(new NoOpProvider(), new NoOpProvider())
.beanFrom(String.class, quote("Some text"));
.beanFrom(String.class, q("Some text"));
assertEquals("Some text", result);

// Plus nulls fine too
result = jsonWithProviders(null, new OverrideStringReaderProvider("foo"))
.beanFrom(String.class, quote("Some text"));
.beanFrom(String.class, q("Some text"));
assertEquals("foo", result);
result = jsonWithProviders(new OverrideStringReaderProvider("foo"), null)
.beanFrom(String.class, quote("Some text"));
.beanFrom(String.class, q("Some text"));
assertEquals("foo", result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void testCustomBeanWriter() throws Exception
assertEquals("{\"wrapped\":{}}", JSON.std.asString(new CustomBeanWrapper()));

final JSON withCustom = jsonWithProvider(new CustomWriters());
assertEquals(quote("xxx"), withCustom.asString(new CustomBean()));
assertEquals(q("xxx"), withCustom.asString(new CustomBean()));
assertEquals("{\"wrapped\":\"xxx\"}", withCustom.asString(new CustomBeanWrapper()));
assertEquals("[\"xxx\"]", withCustom.asString(new CustomBean[] { new CustomBean() }));
assertEquals("{\"value\":\"xxx\"}",
Expand All @@ -100,18 +100,18 @@ public void testCustomBeanWriter() throws Exception

public void testChainedBeanWriters() throws Exception
{
assertEquals(quote("abc"),
assertEquals(q("abc"),
jsonWithProviders(new CustomWriters("abc"), new CustomWriters("def"))
.asString(new CustomBean()));
assertEquals(quote("def"),
assertEquals(q("def"),
jsonWithProviders(new BogusProvider(), new CustomWriters("def"))
.asString(new CustomBean()));

// as well as passing `null`
assertEquals(quote("xxx"),
assertEquals(q("xxx"),
jsonWithProviders(null, new CustomWriters("xxx"))
.asString(new CustomBean()));
assertEquals(quote("yyy"),
assertEquals(q("yyy"),
jsonWithProviders(new CustomWriters("yyy"), null)
.asString(new CustomBean()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public ValueReader modifyValueReader(JSONReader readContext,

public void testStringReaderReplacement() throws Exception
{
final String input = quote("foobar");
final String input = q("foobar");
assertEquals("foobar", JSON.std.beanFrom(String.class, input));

// but then with modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public Class<?> valueType() {
final String input = "foobar";
final JSON jsonWithMod = jsonWithModifier(mod);
String result = jsonWithMod.asString(input);
assertEquals(quote("FOOBAR"), result);
assertEquals(q("FOOBAR"), result);
// but also verify that no caching occurs wrt global standard variant:
assertEquals(quote("foobar"), JSON.std.asString(input));
assertEquals(q("foobar"), JSON.std.asString(input));

// And then also applicable for multiple POJO properties
assertEquals(a2q("{'first':'BOB','last':'HOPE'}"),
Expand Down Expand Up @@ -136,7 +136,7 @@ public Class<?> valueType() {
});
final NameBean input = new NameBean("Foo", "Bar");
String json = jsonWithModifier(mod).asString(input);
assertEquals(quote("Foo-Bar"), json);
assertEquals(q("Foo-Bar"), json);
// but also verify that no caching occurs wrt global standard variant:
assertEquals(a2q("{'first':'Foo','last':'Bar'}"),
JSON.std.asString(input));
Expand Down

0 comments on commit f406086

Please # to comment.