List of usage examples for org.json.simple JSONValue toJSONString
public static String toJSONString(Object value)
From source file:org.biokoframework.system.repository.memory.MemoryRepositoryTest.java
@Test public void getEntitiesByForeignKeyTest() { try {//w w w . ja v a 2s. c om ASDummyEntity1Builder builder = fInjector.getInstance(ASDummyEntity1Builder.class); // case sensitive correct case List<ASDummyEntity1> gruppo1Entities = fRepo.getEntitiesByForeignKey(ASDummyEntity1.GROUP, "gruppo1"); System.out.println(JSONValue.toJSONString(gruppo1Entities)); System.out.println("["); System.out.println(builder.loadExample(ASDummyEntity1Builder.EXAMPLE_GINO).build(true).toJSONString()); System.out.println(builder.loadExample(ASDummyEntity1Builder.EXAMPLE_PINO).build(true).toJSONString()); System.out.println("]"); assertThat(gruppo1Entities.toArray(new ASDummyEntity1[0]), arrayContainingInAnyOrder(builder.loadExample(ASDummyEntity1Builder.EXAMPLE_GINO).build(true), builder.loadExample(ASDummyEntity1Builder.EXAMPLE_PINO).build(true))); // case sensitive, with wrong case List<ASDummyEntity1> gruppo1Entities2 = fRepo.getEntitiesByForeignKey(ASDummyEntity1.GROUP, "Gruppo1"); assertEquals(0, gruppo1Entities2.size()); // case insensitive, with correct case List<ASDummyEntity1> gruppo1Entities3 = fRepo.getEntitiesByForeignKey(ASDummyEntity1.GROUP, "gruppo1"); assertThat(gruppo1Entities3.toArray(new ASDummyEntity1[0]), arrayContainingInAnyOrder(builder.loadExample(ASDummyEntity1Builder.EXAMPLE_GINO).build(true), builder.loadExample(ASDummyEntity1Builder.EXAMPLE_PINO).build(true))); // case insensitive, with wrong case // List<ASDummyEntity1> gruppo1Entities4 = repo.getEntitiesByForeignKey(ASDummyEntity1.GROUP, "Gruppo1", true); // assertThat(gruppo1Entities4.toArray(new ASDummyEntity1[0]), arrayContainingInAnyOrder( // builder.loadExample(ASDummyEntity1Builder.EXAMPLE_GINO).build(true), // builder.loadExample(ASDummyEntity1Builder.EXAMPLE_PINO).build(true) // )); } catch (Exception e) { if (e instanceof ValidationException) { System.err.println(">>> validation ex >>>"); ValidationException ve = (ValidationException) e; System.err.println(JSONValue.toJSONString(ve.getErrors())); } else { e.printStackTrace(); } } // // assertEquals(builder.loadExample(ASDummyEntity1Builder.EXAMPLE_GINO).build(true).get(ASDummyEntity1.ID), ginoEntity.get(ASDummyEntity1.ID)); // // case sensitive, with wrong case // ASDummyEntity1 ginoEntity2 = repo.retrieveByForeignKey(ASDummyEntity1.VALUE, "Gino"); // assertEquals(null, ginoEntity2); // // case insensitive, with correct case // ASDummyEntity1 ginoEntity3 = repo.retrieveByForeignKey(ASDummyEntity1.VALUE, "gino", true); // assertEquals(builder.loadExample(ASDummyEntity1Builder.EXAMPLE_GINO).build(true).get(ASDummyEntity1.ID), ginoEntity3.get(ASDummyEntity1.ID)); // // ,case insensitive, with wrong case // ASDummyEntity1 ginoEntity4 = repo.retrieveByForeignKey(ASDummyEntity1.VALUE, "Gino", true); // assertEquals(builder.loadExample(ASDummyEntity1Builder.EXAMPLE_GINO).build(true).get(ASDummyEntity1.ID), ginoEntity4.get(ASDummyEntity1.ID)); }
From source file:org.biokoframework.system.service.description.JsonEntityDescription.java
@Override public String toJSONString() { return JSONValue.toJSONString(_fields); }
From source file:org.biokoframework.system.service.description.JsonFieldDescription.java
@Override public String toJSONString() { if (!_hints.isEmpty()) { _internalRepresentation.put(HINTS, _hints); }/* w ww . j a v a2 s .com*/ return JSONValue.toJSONString(_internalRepresentation); }
From source file:org.biokoframework.system.service.description.JsonSystemDescription.java
@Override public String toJSONString() { HashMap<String, Object> internalRepresentation = new HashMap<String, Object>(); internalRepresentation.put(ENTITIES, _entityDescriptions); // internalRepresentation.put(COMMANDS, _commandDescriptions); return JSONValue.toJSONString(internalRepresentation); }
From source file:org.biokoframework.utils.exception.BiokoException.java
@Override public String getMessage() { if (fErrors != null) { return JSONValue.toJSONString(fErrors); } else {// www .jav a 2 s .c om return super.getMessage(); } }
From source file:org.biokoframework.utils.json.FieldsToJsonTest.java
@SuppressWarnings("unchecked") @Test//from w ww.j a v a 2 s . com public void arrayOfDomainAntityFieldsToJson() throws Exception { ArrayList<AnnotatedPersonExample> domainEntityArray = new ArrayList<AnnotatedPersonExample>(); AnnotatedPersonExample mattoEntity = new AnnotatedPersonExample(); mattoEntity.setAll(FieldsMother.twoFields()); AnnotatedPersonExample paoloEntity = new AnnotatedPersonExample(); paoloEntity.setAll(FieldsMother.twoFields()); domainEntityArray.add(mattoEntity); domainEntityArray.add(paoloEntity); String aKey = "domainEntityArray"; Fields fields = new Fields(aKey, domainEntityArray); JSONObject jsonObject = new JSONObject(); jsonObject.put(aKey, domainEntityArray); String jsonString = JSONValue.toJSONString(jsonObject); assertThat(jsonString, is(equalTo(fields.toJSONString()))); }
From source file:org.biokoframework.utils.json.FieldsToJsonTest.java
@SuppressWarnings("unchecked") @Test//from ww w . jav a 2s . c o m public void fieldsAndarrayOfDomainAntityToJson() throws Exception { ArrayList<AnnotatedPersonExample> domainEntityArray = new ArrayList<AnnotatedPersonExample>(); AnnotatedPersonExample mattoEntity = new AnnotatedPersonExample(); mattoEntity.setAll(FieldsMother.twoFields()); AnnotatedPersonExample paoloEntity = new AnnotatedPersonExample(); paoloEntity.setAll(FieldsMother.twoFields()); domainEntityArray.add(mattoEntity); domainEntityArray.add(paoloEntity); String aKey = "domainEntityArray"; Fields arrayOfDomainEntity = new Fields(aKey, domainEntityArray); Fields fields = FieldsMother.twoFields().putAll(arrayOfDomainEntity); JSONObject jsonObject = new JSONObject(); jsonObject.put(FieldNames.NAME, FieldNames.NAME_VALUE); jsonObject.put(FieldNames.SURNAME, FieldNames.SURNAME_VALUE); jsonObject.put(aKey, domainEntityArray); String jsonString = JSONValue.toJSONString(jsonObject); assertThat(jsonString, is(equalTo(fields.toJSONString()))); }
From source file:org.biokoframework.utils.json.JSonBuilder.java
public String buildFrom(Fields someFields) { if (!someFields.isEmpty()) { for (String each : someFields.keys()) { Object value = someFields.get(each); if (value != null) add(each, value);//from w w w.ja va2s . com else System.out.println(each + " - is null"); } } // TODO verificare che non sia questo che cambia l'escaping return JSONValue.toJSONString(fJsonObject); }
From source file:org.cgiar.dapa.ccafs.tpe.geojson.GeoJsonTest.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public void testCreatGeoJson() { // JSONObject object = new JSONObject(); // JSONParser parser = new JSONParser(); Map obj = new LinkedHashMap(); obj.put("name", "abia"); obj.put("point", new Integer(100)); obj.put("yield", new Double(1000.21)); String jsonText = JSONValue.toJSONString(obj); log.info(jsonText);//ww w .jav a 2s .c om }
From source file:org.cgiar.dapa.ccafs.tpe.geojson.GeoJsonTest.java
public void testGetGeoJson() { GeometryPoint geom = new GeometryPoint(new LinkedList<Double>(Arrays.asList(10.2255, 24.77))); // Property property = new Property("yield", 5433.29); Map<String, Object> properties = props; SFeature feature = new SFeature(GEOJSON_VALUE_FEATURE, geom, properties); // The feature collection Map<String, Object> featureCollection = new LinkedHashMap<String, Object>(); // The feature featureCollection.put(GEOJSON_KEY_TYPE, GEOJSON_VALUE_FEATURE_COLLECTION); featureCollection.put(GEOJSON_KEY_FEATURES, new LinkedList<SFeature>(Arrays.asList(feature, feature, feature))); String geoJSON = JSONValue.toJSONString(featureCollection); log.info(geoJSON);/* ww w . j a v a 2 s.c om*/ }