use of org.apache.pivot.json.JSONSerializer in project pivot by apache.
the class ListView method setListData.
/**
* Sets the list data.
*
* @param listData A URL referring to a JSON file containing the data to be
* presented by the list view.
* @throws IllegalArgumentException if the list data URL is {@code null}
* or if there is any kind of error trying to retrieve the list data from
* that location.
*/
public void setListData(URL listData) {
Utils.checkNull(listData, "listData");
JSONSerializer jsonSerializer = new JSONSerializer();
try {
setListData((List<?>) jsonSerializer.readObject(listData.openStream()));
} catch (SerializationException exception) {
throw new IllegalArgumentException(exception);
} catch (IOException exception) {
throw new IllegalArgumentException(exception);
}
}
use of org.apache.pivot.json.JSONSerializer in project pivot by apache.
the class TableView method setTableData.
/**
* Sets the table data.
*
* @param tableData A URL referring to a JSON file containing the data to be
* presented by the table view.
*/
public void setTableData(URL tableData) {
Utils.checkNull(tableData, "URL for table data");
JSONSerializer jsonSerializer = new JSONSerializer();
try {
setTableData((List<?>) jsonSerializer.readObject(tableData.openStream()));
} catch (SerializationException exception) {
throw new IllegalArgumentException(exception);
} catch (IOException exception) {
throw new IllegalArgumentException(exception);
}
}
use of org.apache.pivot.json.JSONSerializer in project pivot by apache.
the class BindTest method testUntypedList.
/**
* Tests returning an untyped list.
*
* @throws IOException
* @throws SerializationException
*/
@Test
public void testUntypedList() throws IOException, SerializationException {
JSONSerializer listSerializer = new JSONSerializer(ArrayList.class);
List<?> list = (List<?>) listSerializer.readObject(new StringReader("[1, 2, 3, 4, 5]"));
assertEquals(list.get(0), 1);
}
use of org.apache.pivot.json.JSONSerializer in project pivot by apache.
the class BindTest method testListSubclass.
/**
* Tests returning a subclass of a generic
* {@code org.apache.pivot.collections.List}.
*
* @throws IOException
* @throws SerializationException
*/
@Test
public void testListSubclass() throws IOException, SerializationException {
JSONSerializer listSerializer = new JSONSerializer();
@SuppressWarnings("unchecked") List<Object> list = (List<Object>) listSerializer.readObject(getClass().getResourceAsStream("list.json"));
JSONSerializer typedListSerializer = new JSONSerializer(SampleBean2ListSubclass.class);
SampleBean2List typedList = (SampleBean2List) typedListSerializer.readObject(getClass().getResourceAsStream("list.json"));
Object item0 = typedList.get(0);
assertTrue(item0 instanceof SampleBean2);
assertEquals((Integer) typedList.get(0).getA(), (Integer) JSON.get(list, "[0].a"));
}
use of org.apache.pivot.json.JSONSerializer in project pivot by apache.
the class BindTest method testSequence.
/**
* Tests returning a class that implements
* {@code org.apache.pivot.collections.Sequence}.
*
* @throws IOException
* @throws SerializationException
*/
@Test
public void testSequence() throws IOException, SerializationException {
JSONSerializer listSerializer = new JSONSerializer();
@SuppressWarnings("unchecked") List<Object> list = (List<Object>) listSerializer.readObject(getClass().getResourceAsStream("list.json"));
JSONSerializer sequenceSerializer = new JSONSerializer(SampleBean2SequenceSubclass.class);
SampleBean2Sequence sequence = (SampleBean2Sequence) sequenceSerializer.readObject(getClass().getResourceAsStream("list.json"));
Object item0 = sequence.get(0);
assertNotNull(item0);
// assertTrue(item0 instanceof SampleBean2); // true but superfluous
assertEquals((Integer) sequence.get(0).getA(), (Integer) JSON.get(list, "[0].a"));
}
Aggregations