Ejemplo n.º 1
0
  /** Tests deserialize and getters. */
  @Test
  public void testDeserialize() throws Exception {
    LLC llc = deserializer.deserialize(bytes, 0, bytes.length);

    assertEquals(dsap, llc.getDsap());
    assertEquals(ssap, llc.getSsap());
    assertEquals(ctrl, llc.getCtrl());
  }
Ejemplo n.º 2
0
  /** Tests toString. */
  @Test
  public void testToStringLLC() throws Exception {
    LLC llc = deserializer.deserialize(bytes, 0, bytes.length);
    String str = llc.toString();

    assertTrue(StringUtils.contains(str, "dsap=" + dsap));
    assertTrue(StringUtils.contains(str, "ssap=" + ssap));
    assertTrue(StringUtils.contains(str, "ctrl=" + ctrl));
  }
  public Object deserialize(Object o, Class clazz) throws DeserializationException {
    Object result = null;

    try {
      Assert.assertNotNull(o, "Input parameter [" + o + "] cannot be null");
      Assert.assertNotNull(o, "Input parameter [" + clazz + "] cannot be null");

      SourceBean xml = null;
      if (o instanceof SourceBean) {
        xml = (SourceBean) o;
      } else if (o instanceof String) {
        xml = SourceBean.fromXMLString((String) o);
      } else {
        throw new DeserializationException(
            "Impossible to deserialize from an object of type [" + o.getClass().getName() + "]");
      }

      Deserializer deserializer = mappings.get(clazz);
      if (deserializer == null) {
        throw new DeserializationException(
            "Impossible to deserialize to an object of type [" + clazz.getName() + "]");
      }

      if (xml.getAttribute("ROWS") != null) {
        List list = new ArrayList();
        List<SourceBean> rows = xml.getAttributeAsList("ROWS.ROW");
        for (SourceBean row : rows) {
          list.add(deserializer.deserialize(row, clazz));
        }
        result = list;
      } else {
        result = deserializer.deserialize(o, clazz);
      }
    } catch (Throwable t) {
      throw new DeserializationException("An error occurred while deserializing object: " + o, t);
    } finally {

    }

    return result;
  }
Ejemplo n.º 4
0
  public static <T> T parse(Object object, Type type) {

    Deserializer deserializer = getDeserializer(type);

    return deserializer.deserialize(object, type);
  }