private void showCurrentTile () { if (null == _pyramidId) return; if (null == _pyramidIO) return; if (null == _levelField.getSelectedItem()) return; if (null == _xField.getSelectedItem()) return; if (null == _yField.getSelectedItem()) return; TileIndex index = new TileIndex((Integer) _levelField.getSelectedItem(), (Integer) _xField.getSelectedItem(), (Integer) _yField.getSelectedItem()); try { InputStream tileStream = _pyramidIO.getTileStream(_pyramidId, null, index); _tile = AvroJSONConverter.convert(tileStream); if (null == _tile) { _tileVis.setText(""); } else { _tileVis.setText(_tile.toString(2)); } } catch (Exception e) { _tileVis.setText(""); } }
@Test public void testSimpleRecord () throws IOException, JSONException { Schema schema = new Parser().parse("{ \"name\": \"test\", \"type\": \"record\", \"fields\": [ { \"name\": \"value\", \"type\": \"double\" } ] }"); GenericRecord record = new GenericData.Record(schema); record.put("value", 3.4); JSONObject result = AvroJSONConverter.convert(toInputStream(schema, record)); Assert.assertEquals(3.4, result.getDouble("value"), EPSILON); }
JSONObject deserializedJSON = AvroJSONConverter.convert( tile ); return transformer.transform( deserializedJSON );
@Test public void testReadWordScoreTile () throws IOException, JSONException { // Create a tile to test TileSerializer<List<Pair<String, Double>>> serializer = new PairArrayAvroSerializer<>(String.class, Double.class, CodecFactory.nullCodec()); TileIndex index = new TileIndex(0, 0, 0, 1, 1); DenseTileData<List<Pair<String, Double>>> tile = new DenseTileData<>(index); List<Pair<String, Double>> bin = new ArrayList<>(); bin.add(new Pair<String, Double>("abc", 1.0)); bin.add(new Pair<String, Double>("def", 1.5)); bin.add(new Pair<String, Double>("ghi", 2.0)); bin.add(new Pair<String, Double>("jkl", 2.25)); tile.setBin(0, 0, bin); ByteArrayOutputStream baos = new ByteArrayOutputStream(); serializer.serialize(tile, baos); baos.flush(); baos.close(); byte[] serializedTileData = baos.toByteArray(); // Now try to convert that to JSON. JSONObject result = AvroJSONConverter.convert(new ByteArrayInputStream(serializedTileData)); System.out.println(result.toString()); } }
record.put("dval", 3.6); JSONObject result = AvroJSONConverter.convert(toInputStream(schema, record)); Assert.assertEquals(3.6, result.getDouble("dval"), EPSILON); JSONObject subResult = result.getJSONObject("rval");