@Test public void testToJSON() { Map<String, Object> embedded = new HashMap<>(); embedded.put("a", 1); List<Object> array = Arrays.asList(1, embedded, Arrays.asList(1, 2, 3), new String[]{"a", "b", "c"}); final PJsonArray test = new PYamlArray(null, array, "test").toJSON(); assertEquals(4, test.size()); assertEquals(1, test.get(0)); final JSONObject embeddedJson = (JSONObject) test.get(1); assertEquals(1, embeddedJson.length()); assertEquals(1, embeddedJson.getInt("a")); final JSONArray array1 = (JSONArray) test.get(2); assertEquals(3, array1.length()); assertEquals(1, array1.getInt(0)); assertEquals(2, array1.getInt(1)); assertEquals(3, array1.getInt(2)); final JSONArray array2 = (JSONArray) test.get(3); assertEquals(3, array2.length()); assertEquals("a", array2.getString(0)); assertEquals("b", array2.getString(1)); assertEquals("c", array2.getString(2)); assertTrue(test.getArray(3) instanceof PJsonArray); assertNotNull(test.getJSONArray(3)); }
public final PJsonArray toJSON() { JSONArray jsonArray = new JSONArray(); final int size = this.array.size(); for (int i = 0; i < size; i++) { final Object o = get(i); if (o instanceof PYamlObject) { PYamlObject pYamlObject = (PYamlObject) o; jsonArray.put(pYamlObject.toJSON().getInternalObj()); } else if (o instanceof PYamlArray) { PYamlArray pYamlArray = (PYamlArray) o; jsonArray.put(pYamlArray.toJSON().getInternalArray()); } else { jsonArray.put(o); } } return new PJsonArray(null, jsonArray, getContextName()); }
PYamlArray extends PElement implements PArray { public final PJsonArray toJSON() { JSONArray jsonArray = new JSONArray(); final int size = this.array.size(); for (int i = 0; i < size; i++) { final Object o = get(i); if (o instanceof PYamlObject) { PYamlObject pYamlObject = (PYamlObject) o; jsonArray.put(pYamlObject.toJSON().getInternalObj()); } else if (o instanceof PYamlArray) { PYamlArray pYamlArray = (PYamlArray) o; jsonArray.put(pYamlArray.toJSON().getInternalArray()); } else { jsonArray.put(o); } } return new PJsonArray(null, jsonArray, getContextName()); } }
PYamlArray extends PElement implements PArray { public final PJsonArray toJSON() { JSONArray jsonArray = new JSONArray(); final int size = this.array.size(); for (int i = 0; i < size; i++) { final Object o = get(i); if (o instanceof PYamlObject) { PYamlObject pYamlObject = (PYamlObject) o; jsonArray.put(pYamlObject.toJSON().getInternalObj()); } else if (o instanceof PYamlArray) { PYamlArray pYamlArray = (PYamlArray) o; jsonArray.put(pYamlArray.toJSON().getInternalArray()); } else { jsonArray.put(o); } } return new PJsonArray(null, jsonArray, getContextName()); } PYamlArray(final PElement parent, final List<Object> array, final String contextName); }
PYamlArray extends PElement implements PArray { public final PJsonArray toJSON() { JSONArray jsonArray = new JSONArray(); final int size = this.array.size(); for (int i = 0; i < size; i++) { final Object o = get(i); if (o instanceof PYamlObject) { PYamlObject pYamlObject = (PYamlObject) o; jsonArray.put(pYamlObject.toJSON().getInternalObj()); } else if (o instanceof PYamlArray) { PYamlArray pYamlArray = (PYamlArray) o; jsonArray.put(pYamlArray.toJSON().getInternalArray()); } else { jsonArray.put(o); } } return new PJsonArray(null, jsonArray, getContextName()); } PYamlArray(final PElement parent, final List<Object> array, final String contextName); @Override final int size(); @Override final PObject getObject(final int i); @Override final PArray getArray(final int i); @Override final int getInt(final int i); @Override final long getLong(final int i); @Override final float getFloat(final int i); @Override final double getDouble(final int i); @Override final String getString(final int i); @Override final boolean getBool(final int i); @SuppressWarnings("unchecked") @Override final Object get(final int i); @Override final String toString(); final PJsonArray toJSON(); }
PYamlArray extends PElement implements PArray { public final PJsonArray toJSON() { JSONArray jsonArray = new JSONArray(); final int size = this.array.size(); for (int i = 0; i < size; i++) { final Object o = get(i); if (o instanceof PYamlObject) { PYamlObject pYamlObject = (PYamlObject) o; jsonArray.put(pYamlObject.toJSON().getInternalObj()); } else if (o instanceof PYamlArray) { PYamlArray pYamlArray = (PYamlArray) o; jsonArray.put(pYamlArray.toJSON().getInternalArray()); } else { jsonArray.put(o); } } return new PJsonArray(null, jsonArray, getContextName()); } PYamlArray(final PElement parent, final List<Object> array, final String contextName); @Override final int size(); @Override final PObject getObject(final int i); @Override final PArray getArray(final int i); @Override final int getInt(final int i); @Override final long getLong(final int i); @Override final float getFloat(final int i); @Override final double getDouble(final int i); @Override final String getString(final int i); @Override final boolean getBool(final int i); @SuppressWarnings("unchecked") @Override final Object get(final int i); @Override final String toString(); final PJsonArray toJSON();  }