本文整理汇总了Java中ca.uqac.lif.azrael.SerializerException类的典型用法代码示例。如果您正苦于以下问题:Java SerializerException类的具体用法?Java SerializerException怎么用?Java SerializerException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerializerException类属于ca.uqac.lif.azrael包,在下文中一共展示了SerializerException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testList1
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
@Test
public void testList1() throws SerializerException
{
List<Integer> obj_a = new LinkedList<Integer>();
obj_a.add(1);
obj_a.add(2);
obj_a.add(3);
JsonElement e = m_serializer.serialize(obj_a);
assertNotNull(e);
assertTrue("Serialized element should be a list, got a " + e.getClass().getSimpleName(), e instanceof JsonList);
JsonList e_list = (JsonList) e;
assertEquals(3, e_list.size());
Object o_des = m_serializer.deserializeAs(e, LinkedList.class);
assertNotNull(o_des);
assertTrue("Object should be an instance of LinkedList, got " + o_des.getClass().getSimpleName(), o_des instanceof LinkedList);
}
示例2: testJsonList1
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
@Test
public void testJsonList1() throws SerializerException
{
List<JsonElement> obj_a = new LinkedList<JsonElement>();
obj_a.add(new JsonString("1"));
obj_a.add(new JsonString("2"));
obj_a.add(new JsonNumber(3));
JsonElement e = m_serializer.serialize(obj_a);
assertNotNull(e);
assertTrue("Serialized element should be a list, got a " + e.getClass().getSimpleName(), e instanceof JsonList);
JsonList e_list = (JsonList) e;
assertEquals(3, e_list.size());
Object o_des = m_serializer.deserializeAs(e, LinkedList.class);
assertNotNull(o_des);
assertTrue("Object should be an instance of LinkedList, got " + o_des.getClass().getSimpleName(), o_des instanceof LinkedList);
Object l_elem;
l_elem = ((LinkedList<?>) o_des).get(0);
assertTrue(l_elem instanceof JsonString);
l_elem = ((LinkedList<?>) o_des).get(1);
assertTrue(l_elem instanceof JsonString);
l_elem = ((LinkedList<?>) o_des).get(2);
assertTrue(l_elem instanceof JsonNumber);
}
示例3: testSet1
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
@Test
public void testSet1() throws SerializerException
{
Set<Integer> obj_a = new HashSet<Integer>();
obj_a.add(1);
obj_a.add(2);
obj_a.add(3);
JsonElement e = m_serializer.serialize(obj_a);
assertNotNull(e);
assertTrue("Serialized element should be a list, got a " + e.getClass().getSimpleName(), e instanceof JsonList);
JsonList e_list = (JsonList) e;
assertEquals(3, e_list.size());
Object o_des = m_serializer.deserializeAs(e, HashSet.class);
assertNotNull(o_des);
assertTrue("Object should be an instance of HashSet, got " + o_des.getClass().getSimpleName(), o_des instanceof HashSet);
}
示例4: testMap1
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
@Test
public void testMap1() throws SerializerException
{
Map<String,Integer> obj_a = new HashMap<String,Integer>();
obj_a.put("a", 1);
obj_a.put("b", 2);
obj_a.put("c", 3);
JsonElement e = m_serializer.serialize(obj_a);
assertNotNull(e);
assertTrue("Serialized element should be a list, got a " + e.getClass().getSimpleName(), e instanceof JsonList);
JsonList e_list = (JsonList) e;
assertEquals(3, e_list.size());
Object o_des = m_serializer.deserializeAs(e, HashMap.class);
assertNotNull(o_des);
assertTrue("Object should be an instance of HashMap, got " + o_des.getClass().getSimpleName(), o_des instanceof HashMap);
@SuppressWarnings("unchecked")
HashMap<String,Integer> o_map = (HashMap<String,Integer>) o_des;
assertEquals(1, (int) o_map.get("a"));
}
示例5: testJson1
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
@Test
public void testJson1() throws SerializerException
{
JsonMap jm = new JsonMap();
jm.put("a", 1);
JsonList jl = new JsonList();
jl.add("b");
jm.put("z", jl);
JsonElement e = m_serializer.serialize(jm);
assertNotNull(e);
assertTrue("Serialized element should be a map, got a " + e.getClass().getSimpleName(), e instanceof JsonMap);
Object o_des = m_serializer.deserializeAs(e, JsonMap.class);
assertNotNull(o_des);
assertTrue("Object should be an instance of JsonMap, got " + o_des.getClass().getSimpleName(), o_des instanceof JsonMap);
JsonMap o_map = (JsonMap) o_des;
assertEquals(1, (int) o_map.getNumber("a").intValue());
}
示例6: getElements
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
@Override
protected List<JsonElement> getElements(JsonElement e) throws SerializerException
{
JsonElement je = m_serializer.unwrapTypeInfo(e);
if (je == null || !(je instanceof JsonList))
{
throw new SerializerException("Input must be a JSON list");
}
JsonList j_list = (JsonList) je;
List<JsonElement> elements = new LinkedList<JsonElement>();
for (JsonElement el : j_list)
{
elements.add(el);
}
return elements;
}
示例7: getElements
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
@Override
protected Set<JsonElement> getElements(JsonElement e) throws SerializerException
{
JsonElement je = m_serializer.unwrapTypeInfo(e);
if (je == null || !(je instanceof JsonList))
{
throw new SerializerException("Input must be a JSON list");
}
JsonList j_list = (JsonList) je;
Set<JsonElement> elements = new HashSet<JsonElement>();
for (JsonElement el : j_list)
{
elements.add(el);
}
return elements;
}
示例8: saveToJson
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
/**
* Saves the state of the lab to a JSON element
* @return The JSON element with the assistant's state, or null
* if some error occurred
*/
public JsonElement saveToJson()
{
/* NOTE: this method should instead throw the exception and let
* higher levels of the GUI handle it, rather than silently fail
*/
try
{
JsonElement js_out = m_serializer.serializeAs(this, this.getClass());
return js_out;
}
catch (SerializerException e)
{
// Do nothing
}
return null;
}
示例9: loadFromZip
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
/**
* Loads a laboratory from an input stream containing a zip file
* @param is The input stream
* @return A new lab instance
* @throws IOException
* @throws SerializerException
* @throws JsonParseException
*/
public final Laboratory loadFromZip(InputStream is) throws IOException, SerializerException, JsonParseException
{
ZipInputStream zis = new ZipInputStream(is);
ZipEntry entry;
entry = zis.getNextEntry();
byte[] contents = null;
while (entry != null)
{
//String name = entry.getName();
contents = HttpUtilities.extractFile(zis);
// We assume the zip to contain a single file
break;
}
String json = new String(contents);
return loadFromString(json);
}
示例10: getFromZip
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
/**
* Creates a new lab instance from the contents of a zip file
* @param lab_file_contents
* @return The lab
* @throws IOException
* @throws SerializerException
* @throws JsonParseException
*/
public Laboratory getFromZip(byte[] lab_file_contents) throws IOException, SerializerException, JsonParseException
{
ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(lab_file_contents));
ZipEntry entry;
byte[] contents = null;
entry = zis.getNextEntry();
while (entry != null)
{
//String name = entry.getName();
contents = HttpUtilities.extractFile(zis);
// We assume the zip to contain a single file
break;
}
assert contents != null;
String json = new String(contents);
return loadFromString(json);
}
示例11: testPrimitiveString1
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
@Test
public void testPrimitiveString1() throws SerializerException
{
String obj_a = "abc";
JsonElement e = m_serializer.serialize(obj_a);
assertNotNull(e);
assertTrue("Serialized element should be a String", e instanceof JsonString);
JsonString e_map = (JsonString) e;
assertEquals(3, e_map.stringValue().length());
}
示例12: testPrimitiveString2
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
@Test
public void testPrimitiveString2() throws SerializerException
{
String obj_a = "";
JsonElement e = m_serializer.serialize(obj_a);
assertNotNull(e);
assertTrue("Serialized element should be a String", e instanceof JsonString);
JsonString e_map = (JsonString) e;
assertEquals(0, e_map.stringValue().length());
}
示例13: testPrimitiveBoolean1
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
@Test
public void testPrimitiveBoolean1() throws SerializerException
{
Boolean obj_a = true;
JsonElement e = m_serializer.serialize(obj_a);
assertNotNull(e);
assertTrue("Serialized element should be a String", e instanceof JsonString);
JsonString e_map = (JsonString) e;
assertTrue("Value should be 'true'", e_map.stringValue().compareTo("true") == 0);
}
示例14: testPrimitiveBoolean2
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
@Test
public void testPrimitiveBoolean2() throws SerializerException
{
Boolean obj_a = false;
JsonElement e = m_serializer.serialize(obj_a);
assertNotNull(e);
assertTrue("Serialized element should be a String", e instanceof JsonString);
JsonString e_map = (JsonString) e;
assertTrue("Value should be 'true'", e_map.stringValue().compareTo("false") == 0);
}
示例15: testPrimitiveBoolean3
import ca.uqac.lif.azrael.SerializerException; //导入依赖的package包/类
@Test
public void testPrimitiveBoolean3() throws SerializerException
{
boolean obj_a = true;
JsonElement e = m_serializer.serialize(obj_a);
assertNotNull(e);
assertTrue("Serialized element should be a String", e instanceof JsonString);
JsonString e_map = (JsonString) e;
assertTrue("Value should be 'true'", e_map.stringValue().compareTo("true") == 0);
}