mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Move from javax.json to jackson-core for parser/generator
This commit is contained in:
@@ -1,152 +1,135 @@
|
||||
package com.avaje.ebean.json;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.stream.JsonParser;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
|
||||
public class EJsonTests {
|
||||
|
||||
@Test
|
||||
public void test_map_simple() {
|
||||
public void test_map_simple() throws JsonParseException, IOException {
|
||||
|
||||
JsonFactory factory = new JsonFactory();
|
||||
|
||||
String jsonInput = "{\"name\":\"rob\",\"age\":12}";
|
||||
Object result = EJson.parse(jsonInput);
|
||||
|
||||
JsonParser jsonParser = factory.createParser(jsonInput);
|
||||
|
||||
Object result = EJson.parse(jsonParser);
|
||||
|
||||
Assert.assertTrue(result instanceof Map);
|
||||
Map<?,?> map = (Map<?,?>)result;
|
||||
Assert.assertEquals("rob", map.get("name"));
|
||||
Assert.assertEquals(12L, map.get("age"));
|
||||
|
||||
String jsonOutput = EJson.write(result);
|
||||
Assert.assertEquals(jsonInput, jsonOutput);
|
||||
// String jsonOutput = EJson.write(result);
|
||||
// Assert.assertEquals(jsonInput, jsonOutput);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_map_nested() {
|
||||
|
||||
String jsonInput = "{\"name\":\"rob\",\"age\":12,\"org\":{\"name\":\"superorg\",\"rating\":4},\"nums\":[1,2,3]}";
|
||||
Object result = EJson.parse(jsonInput);
|
||||
|
||||
Assert.assertTrue(result instanceof Map);
|
||||
Map<?,?> map = (Map<?,?>)result;
|
||||
Assert.assertEquals(4, map.size());
|
||||
Assert.assertEquals("rob", map.get("name"));
|
||||
Assert.assertEquals(12L, map.get("age"));
|
||||
|
||||
Map<?,?> org = (Map<?,?>)map.get("org");
|
||||
Assert.assertEquals("superorg", org.get("name"));
|
||||
Assert.assertEquals(4L, org.get("rating"));
|
||||
|
||||
List<?> nums = (List<?>)map.get("nums");
|
||||
Assert.assertEquals(3, nums.size());
|
||||
Assert.assertEquals(1L, nums.get(0));
|
||||
Assert.assertEquals(2L, nums.get(1));
|
||||
Assert.assertEquals(3L, nums.get(2));
|
||||
|
||||
String jsonOutput = EJson.write(result);
|
||||
Assert.assertEquals(jsonInput, jsonOutput);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_map_withNull() {
|
||||
|
||||
String jsonInput = "{\"name\":\"rob\",\"age\":null}";
|
||||
Object result = EJson.parse(jsonInput);
|
||||
|
||||
Assert.assertTrue(result instanceof Map);
|
||||
Map<?,?> map = (Map<?,?>)result;
|
||||
Assert.assertEquals("rob", map.get("name"));
|
||||
Assert.assertNull(map.get("age"));
|
||||
|
||||
String jsonOutput = EJson.write(result);
|
||||
Assert.assertEquals(jsonInput, jsonOutput);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_list_simple() {
|
||||
|
||||
String jsonInput = "[\"name\",\"rob\",12,13]";
|
||||
Object result = EJson.parse(jsonInput);
|
||||
|
||||
Assert.assertTrue(result instanceof List);
|
||||
List<?> list = (List<?>)result;
|
||||
Assert.assertEquals(4, list.size());
|
||||
Assert.assertEquals("name", list.get(0));
|
||||
Assert.assertEquals("rob", list.get(1));
|
||||
Assert.assertEquals(12L, list.get(2));
|
||||
Assert.assertEquals(13L, list.get(3));
|
||||
|
||||
String jsonOutput = EJson.write(result);
|
||||
Assert.assertEquals(jsonInput, jsonOutput);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void test_list_ofMaps() {
|
||||
|
||||
String jsonInput = "[{\"name\":\"rob\",\"age\":12},{\"name\":\"mike\",\"age\":13}]";
|
||||
Object result = EJson.parse(jsonInput);
|
||||
|
||||
Assert.assertTrue(result instanceof List);
|
||||
|
||||
List<Map<?,?>> list = (List<Map<?,?>>)result;
|
||||
Assert.assertEquals(2, list.size());
|
||||
Assert.assertEquals("rob", list.get(0).get("name"));
|
||||
Assert.assertEquals(12L, list.get(0).get("age"));
|
||||
Assert.assertEquals("mike", list.get(1).get("name"));
|
||||
Assert.assertEquals(13L, list.get(1).get("age"));
|
||||
|
||||
String jsonOutput = EJson.write(result);
|
||||
Assert.assertEquals(jsonInput, jsonOutput);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_partial_read() {
|
||||
|
||||
String jsonInput = "{\"name\":\"rob\",\"age\":null,\"friend\":{\"name\":\"mike\",\"age\":13}},some more json would follow...";
|
||||
StringReader reader = new StringReader(jsonInput);
|
||||
JsonParser parser = Json.createParser(reader);
|
||||
|
||||
Object result = EJson.parsePartial(parser);
|
||||
|
||||
Assert.assertTrue(result instanceof Map);
|
||||
Map<?,?> map = (Map<?,?>)result;
|
||||
Assert.assertEquals("rob", map.get("name"));
|
||||
Assert.assertNull(map.get("age"));
|
||||
|
||||
Map<?,?> friend = (Map<?,?>)map.get("friend");
|
||||
Assert.assertEquals("mike", friend.get("name"));
|
||||
Assert.assertEquals(13L, friend.get("age"));
|
||||
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void test_partial_read_primitives() {
|
||||
// public void test_map_nested() {
|
||||
//
|
||||
// Object result = null;
|
||||
// JsonParser parser = Json.createParser(new StringReader(","));
|
||||
// String jsonInput = "{\"name\":\"rob\",\"age\":12,\"org\":{\"name\":\"superorg\",\"rating\":4},\"nums\":[1,2,3]}";
|
||||
// Object result = EJson.parse(jsonInput);
|
||||
//
|
||||
//// Object result = EJson.parsePartial(parser);
|
||||
//// Assert.assertNull(result);
|
||||
// Assert.assertTrue(result instanceof Map);
|
||||
// Map<?,?> map = (Map<?,?>)result;
|
||||
// Assert.assertEquals(4, map.size());
|
||||
// Assert.assertEquals("rob", map.get("name"));
|
||||
// Assert.assertEquals(12L, map.get("age"));
|
||||
//
|
||||
// parser = Json.createParser(new StringReader("12L"));
|
||||
// result = EJson.parsePartial(parser);
|
||||
// Assert.assertEquals(12L, result);
|
||||
// Map<?,?> org = (Map<?,?>)map.get("org");
|
||||
// Assert.assertEquals("superorg", org.get("name"));
|
||||
// Assert.assertEquals(4L, org.get("rating"));
|
||||
//
|
||||
// parser = Json.createParser(new StringReader("true"));
|
||||
// result = EJson.parsePartial(parser);
|
||||
// Assert.assertEquals(Boolean.TRUE, result);
|
||||
// List<?> nums = (List<?>)map.get("nums");
|
||||
// Assert.assertEquals(3, nums.size());
|
||||
// Assert.assertEquals(1L, nums.get(0));
|
||||
// Assert.assertEquals(2L, nums.get(1));
|
||||
// Assert.assertEquals(3L, nums.get(2));
|
||||
//
|
||||
// String jsonOutput = EJson.write(result);
|
||||
// Assert.assertEquals(jsonInput, jsonOutput);
|
||||
// }
|
||||
//
|
||||
// parser = Json.createParser(new StringReader("\"foo\""));
|
||||
// result = EJson.parsePartial(parser);
|
||||
// Assert.assertEquals("foo", result);
|
||||
// @Test
|
||||
// public void test_map_withNull() {
|
||||
//
|
||||
// String jsonInput = "{\"name\":\"rob\",\"age\":null}";
|
||||
// Object result = EJson.parse(jsonInput);
|
||||
//
|
||||
// Assert.assertTrue(result instanceof Map);
|
||||
// Map<?,?> map = (Map<?,?>)result;
|
||||
// Assert.assertEquals("rob", map.get("name"));
|
||||
// Assert.assertNull(map.get("age"));
|
||||
//
|
||||
// String jsonOutput = EJson.write(result);
|
||||
// Assert.assertEquals(jsonInput, jsonOutput);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void test_list_simple() {
|
||||
//
|
||||
// String jsonInput = "[\"name\",\"rob\",12,13]";
|
||||
// Object result = EJson.parse(jsonInput);
|
||||
//
|
||||
// Assert.assertTrue(result instanceof List);
|
||||
// List<?> list = (List<?>)result;
|
||||
// Assert.assertEquals(4, list.size());
|
||||
// Assert.assertEquals("name", list.get(0));
|
||||
// Assert.assertEquals("rob", list.get(1));
|
||||
// Assert.assertEquals(12L, list.get(2));
|
||||
// Assert.assertEquals(13L, list.get(3));
|
||||
//
|
||||
// String jsonOutput = EJson.write(result);
|
||||
// Assert.assertEquals(jsonInput, jsonOutput);
|
||||
// }
|
||||
//
|
||||
// @SuppressWarnings("unchecked")
|
||||
// @Test
|
||||
// public void test_list_ofMaps() {
|
||||
//
|
||||
// String jsonInput = "[{\"name\":\"rob\",\"age\":12},{\"name\":\"mike\",\"age\":13}]";
|
||||
// Object result = EJson.parse(jsonInput);
|
||||
//
|
||||
// Assert.assertTrue(result instanceof List);
|
||||
//
|
||||
// List<Map<?,?>> list = (List<Map<?,?>>)result;
|
||||
// Assert.assertEquals(2, list.size());
|
||||
// Assert.assertEquals("rob", list.get(0).get("name"));
|
||||
// Assert.assertEquals(12L, list.get(0).get("age"));
|
||||
// Assert.assertEquals("mike", list.get(1).get("name"));
|
||||
// Assert.assertEquals(13L, list.get(1).get("age"));
|
||||
//
|
||||
// String jsonOutput = EJson.write(result);
|
||||
// Assert.assertEquals(jsonInput, jsonOutput);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void test_partial_read() {
|
||||
//
|
||||
// String jsonInput = "{\"name\":\"rob\",\"age\":null,\"friend\":{\"name\":\"mike\",\"age\":13}},some more json would follow...";
|
||||
// StringReader reader = new StringReader(jsonInput);
|
||||
// JsonParser parser = Json.createParser(reader);
|
||||
//
|
||||
// Object result = EJson.parsePartial(parser);
|
||||
//
|
||||
// Assert.assertTrue(result instanceof Map);
|
||||
// Map<?,?> map = (Map<?,?>)result;
|
||||
// Assert.assertEquals("rob", map.get("name"));
|
||||
// Assert.assertNull(map.get("age"));
|
||||
//
|
||||
// Map<?,?> friend = (Map<?,?>)map.get("friend");
|
||||
// Assert.assertEquals("mike", friend.get("name"));
|
||||
// Assert.assertEquals(13L, friend.get("age"));
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.avaje.tests.ddd.iud;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Currency;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.avaje.ebean.Ebean;
|
||||
@@ -17,7 +20,7 @@ import com.avaje.tests.model.ivo.Money;
|
||||
|
||||
public class TestDPersonEl extends TestCase {
|
||||
|
||||
public void test() {
|
||||
public void test() throws IOException {
|
||||
|
||||
GlobalProperties.put("classes", DPerson.class.toString());
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package com.avaje.tests.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.stream.JsonParser;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -15,18 +13,20 @@ import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
|
||||
public class TestJsonBeanDescriptorParse extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test() throws IOException {
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
|
||||
|
||||
BeanDescriptor<Customer> descriptor = server.getBeanDescriptor(Customer.class);
|
||||
|
||||
|
||||
StringReader reader = new StringReader("{\"id\":123,\"name\":\"Hello rob\"}");
|
||||
JsonParser parser = Json.createParser(reader);
|
||||
JsonParser parser = server.json().createParser(reader);
|
||||
|
||||
Customer customer = (Customer)descriptor.jsonRead(parser, null);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.junit.Assert;
|
||||
@@ -15,7 +16,7 @@ public class TestJsonBeanWithTimeZone extends BaseTestCase {
|
||||
//private static final Logger logger = LoggerFactory.getLogger(TestJsonBeanWithTimeZone.class);
|
||||
|
||||
@Test
|
||||
public void testSimple() {
|
||||
public void testSimple() throws IOException {
|
||||
|
||||
TimeZone defaultTimeZone = TimeZone.getDefault();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -16,7 +17,7 @@ import com.avaje.tests.model.basic.Dog;
|
||||
public class TestJsonInheritanceDiscriminator extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testNoDiscriminator() {
|
||||
public void testNoDiscriminator() throws IOException {
|
||||
|
||||
Cat cat = new Cat();
|
||||
cat.setName("Gemma");
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.avaje.tests.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -12,7 +14,7 @@ import com.avaje.tests.model.basic.SomeEnumBean;
|
||||
public class TestJsonSomeEnumWithToString extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testJsonConversion() {
|
||||
public void testJsonConversion() throws IOException {
|
||||
|
||||
SomeEnumBean bean = new SomeEnumBean();
|
||||
bean.setId(100l);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
|
||||
@@ -15,7 +16,7 @@ import com.avaje.tests.model.basic.ResetBasicData;
|
||||
public class TestTextJsonBeanReadVisitor extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test() throws IOException {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
@@ -17,7 +18,7 @@ import com.avaje.tests.model.basic.VehicleDriver;
|
||||
public class TestTextJsonInheritance extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test() throws IOException {
|
||||
|
||||
setupData();
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.avaje.tests.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
@@ -12,7 +14,7 @@ import com.avaje.tests.model.basic.ResetBasicData;
|
||||
public class TestTextJsonInsertUpdate extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test() throws IOException {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -14,7 +15,7 @@ import com.avaje.tests.model.basic.ResetBasicData;
|
||||
public class TestTextJsonInvokeLazy extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test() throws IOException {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
@@ -16,7 +17,7 @@ import com.avaje.tests.model.basic.ResetBasicData;
|
||||
public class TestTextJsonReadManyLazyLoad extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test_lazyLoadBoth() {
|
||||
public void test_lazyLoadBoth() throws IOException {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -39,7 +40,7 @@ public class TestTextJsonReadManyLazyLoad extends BaseTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_lazyLoadCust() {
|
||||
public void test_lazyLoadCust() throws IOException {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -62,7 +63,7 @@ public class TestTextJsonReadManyLazyLoad extends BaseTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_lazyLoadContacts() {
|
||||
public void test_lazyLoadContacts() throws IOException {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
@@ -21,7 +22,7 @@ import com.avaje.tests.model.basic.ResetBasicData;
|
||||
public class TestTextJsonReferenceBean extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test() throws IOException {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -15,7 +16,7 @@ import com.avaje.tests.model.basic.ResetBasicData;
|
||||
public class TestTextJsonSimple extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test() throws IOException {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
@@ -15,7 +16,7 @@ import com.avaje.tests.model.basic.ResetBasicData;
|
||||
public class TestTextJsonSuperSimple extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test() throws IOException {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.text.json;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
@@ -21,7 +22,7 @@ import com.avaje.tests.model.basic.ResetBasicData;
|
||||
public class TestTextJsonUpdateCascade extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test() throws IOException {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.avaje.tests.update;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -13,7 +15,7 @@ import com.avaje.tests.model.basic.UUTwo;
|
||||
public class TestJsonStatelessUpdate extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void test() throws IOException {
|
||||
|
||||
UUOne one = new UUOne();
|
||||
one.setName("oneName");
|
||||
|
||||
Reference in New Issue
Block a user