public Result runBoon() { String result = null; String error = null; long time; Iterator<Object> query = null; long now = System.currentTimeMillis(); try { if (!optionAsValues) { throw new UnsupportedOperationException("Not supported!"); } io.gatling.jsonpath.JsonPath jsonPath = JsonPath$.MODULE$.compile(path).right().get(); JsonParser jsonParser = new JsonParserCharArray(); Object jsonModel = jsonParser.parse(json); query = jsonPath.query(jsonModel); } catch (Exception e) { error = getError(e); } finally { time = System.currentTimeMillis() - now; if (query != null) { List<Object> res = new ArrayList<Object>(); while (query.hasNext()) { res.add(query.next()); } ObjectMapper mapper = new ObjectMapperImpl(); result = mapper.toJson(res); } return new Result("boon", time, result, error); } }
@Override public void toJson(Object value, Writer writer) { this.objectMapper.toJson(value, writer); }
@Test public void test() { ObjectMapper mapper = JsonFactory.create(new JsonParserFactory(), new JsonSerializerFactory().setSerializeMapKeys(true).setEncodeStrings(true)); HashMap<String, Object> data = new HashMap<>(); data.put("\"hi\"", Double.parseDouble("1.2312312")); assertEquals("{\"\\\"hi\\\"\":1.2312312}", mapper.toJson(data)); }
@Test public void test_caseInsensitiveProperty_normal() { String json = "{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} "; ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class); puts(json); puts(objectMapper.toJson(map)); assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}"))); }
@Test public void test_stringArrayProperty_fromSingleValue() { String json = "{\"typeName\":\"Processes\",\"descriptions\":\"lala\"}"; ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class); puts(json); puts(objectMapper.toJson(map)); assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"descriptions\":[\"lala\"]}"))); }
@Test public void serializingClassFieldCausesSegFault() { SomeClass someClassInstance = new SomeClass(Bug287.class); ObjectMapper mapper = JsonFactory.create(); final String json = mapper.toJson(someClassInstance); puts(json); SomeClass someClassInstance2 = mapper.readValue("{\"clazz\":\"org.boon.bugs.Bug287\"} ", SomeClass.class); ok = someClassInstance2.clazz.getName().equals("org.boon.bugs.Bug287"); }
@Test public void test_caseInsensitiveProperty_lowercase() { String json = "{\"typename\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} "; ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class); puts(json); puts(objectMapper.toJson(map)); assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}"))); }
@Test public void test_caseInsensitiveProperty_uppercase() { String json = "{\"TYPENAME\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} "; ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class); puts(json); puts(objectMapper.toJson(map)); assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}"))); }
@Test public void test_listProperty() { String json = "{\"typeName\":\"Processes\",\"fields2\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} "; ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class); puts(json); puts(objectMapper.toJson(map)); assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields2\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}"))); }
@Test public void test_caseInsensitiveProperty_lowercase() { String json = "{\"typename\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} "; ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class); puts(json); puts(objectMapper.toJson(map)); assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}"))); }
@Test public void test_arrayProperty_fromSingleValue() { String json = "{\"typeName\":\"Processes\",\"fields\":{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}} "; ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class); puts(json); puts(objectMapper.toJson(map)); assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}"))); }
@Test public void test_listProperty_fromSingleValue() { String json = "{\"typeName\":\"Processes\",\"fields2\":{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}} "; ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class); puts(json); puts(objectMapper.toJson(map)); assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields2\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}"))); }
@Test public void test_stringListProperty_fromSingleValue() { String json = "{\"typeName\":\"Processes\",\"descriptions2\":\"lala\"} "; ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class); puts(json); puts(objectMapper.toJson(map)); assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"descriptions2\":[\"lala\"]}"))); }
@Test public void test_caseInsensitiveProperty_lowercase() { String json = "{\"typename\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} "; ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class); puts(json); puts(objectMapper.toJson(map)); assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}"))); }
@Test public void test_caseInsensitiveProperty_normal() { String json = "{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} "; ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class); puts(json); puts(objectMapper.toJson(map)); assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}"))); }
@Test public void test_caseInsensitiveProperty_normal() { String json = "{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} "; ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class); puts(json); puts(objectMapper.toJson(map)); assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}"))); }
@Test public void test_caseInsensitiveProperty_uppercase() { String json = "{\"TYPENAME\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} "; ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class); puts(json); puts(objectMapper.toJson(map)); assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}"))); }
@Test public void test_arrayProperty() { String json = "{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]} "; ApiDynamicType map = objectMapper.fromJson(json, ApiDynamicType.class); puts(json); puts(objectMapper.toJson(map)); assertThat(objectMapper.fromJson(objectMapper.toJson(map)), is(objectMapper.fromJson("{\"typeName\":\"Processes\",\"fields\":[{\"name\":\"process\",\"type\":\"ConversionRateProcess[]\",\"properties\":[\"REQUIRED\"]}]}"))); }
@Test public void test2() { user = new User("red", "yellow", "green", "purple"); puts(user.getFavoriteColors()); final ObjectMapper objectMapper = JsonFactory.createUseAnnotations(true); json = objectMapper.toJson(user); puts(json); user2 = objectMapper.fromJson(json, User.class); puts(user.getFavoriteColors()); ok = user.equals(user2) || die("Users should be equal", user, user2); }
public void test3() { user = new User("red", "yellow", "green", "purple"); puts(user.getFavoriteColors()); final JsonParserFactory jsonParserFactory = new JsonParserFactory().usePropertiesFirst().useAnnotations(); final JsonSerializerFactory serializerFactory = new JsonSerializerFactory().includeNulls().useAnnotations(); final ObjectMapper objectMapper = new ObjectMapperImpl(jsonParserFactory, serializerFactory); json = objectMapper.toJson(user); puts(json); user2 = objectMapper.fromJson(json, User.class); puts(user.getFavoriteColors()); ok = user.equals(user2) || die("Users should be equal", user, user2); }