@Override protected JSONAnnotation getValue(Object obj) throws JSONException { return JSONAnnotation.fromJSON( (JSONObject)obj ); } }
} catch ( Exception e ) { return new JSONAnnotation( x0, x1, y0, y1, level, range, group, data ); return new JSONAnnotation( x0, x1, y0, y1, level, range, group, uuid, timestamp, data );
public AnnotationData<?> generateJSONAnnotation() { return JSONAnnotation.fromJSON(generateJSON()); }
public synchronized AnnotationData<?> clone() { JSONObject json = _data.toJSON(); return JSONAnnotation.fromJSON( json ); }
JSONAnnotation annotation = JSONAnnotation.fromJSON( json.getJSONObject("annotation") ); Pair<String, Long> certificate = _service.write( layer, annotation ); jsonResult.put("uuid", certificate.getFirst() ); JSONAnnotation annotation = JSONAnnotation.fromJSON( json.getJSONObject("annotation") ); Pair<String, Long> certificate = _service.modify(layer, annotation); jsonResult.put("uuid", certificate.getFirst() );
private AnnotationData<?> editAnnotation( AnnotationData<?> annotation ) { JSONObject json = annotation.toJSON(); AnnotationGenerator generator = new AnnotationGenerator( BOUNDS, _groups ); try { int type = (int)(Math.random() * 2); switch (type) { case 0: // change position double [] xy = generator.randomPosition(); json.put("x", xy[0]); json.put("y", xy[1]); break; default: // change data JSONObject data = new JSONObject(); data.put("comment", generator.randomComment() ); json.put("data", data); break; } } catch ( Exception e ) { e.printStackTrace(); } return JSONAnnotation.fromJSON(json); } }
@Test public void jsonAnnotationToFromTest () throws Exception { AnnotationGenerator generator = new AnnotationGenerator( BOUNDS, GROUPS ); List<AnnotationData<?>> before = generator.generateJSONAnnotations( NUM_ENTRIES ); List<AnnotationData<?>> after = new ArrayList<>(); AnnotationUtil.printData( before ); for ( AnnotationData<?> annotation : before ) { JSONObject json = annotation.toJSON(); after.add( JSONAnnotation.fromJSON(json) ); } AnnotationUtil.printData( after ); Assert.assertTrue( AnnotationUtil.compareData( before, after ) ); }
@Test public void jsonAnnotationToFromTest () throws Exception { AnnotationGenerator generator = new AnnotationGenerator( BOUNDS, GROUPS ); List<AnnotationData<?>> before = generator.generateJSONAnnotations( NUM_ENTRIES ); List<AnnotationData<?>> after = new ArrayList<>(); AnnotationUtil.printData( before ); for ( AnnotationData<?> annotation : before ) { JSONObject json = annotation.toJSON(); after.add( JSONAnnotation.fromJSON(json) ); } AnnotationUtil.printData( after ); Assert.assertTrue( AnnotationUtil.compareData( before, after ) ); }