@Override
  public String doNotNullMarshall(final Object o, final MarshallingSession ctx) {
    Throwable cause = getCause(((Throwable) o));
    String message = null;
    if (cause != null) {
      message = cause.getMessage();
    }

    return "{\""
        + SerializationParts.ENCODED_TYPE
        + "\":\""
        + RuntimeException.class.getName()
        + "\","
        + "\""
        + SerializationParts.OBJECT_ID
        + "\":\""
        + o.hashCode()
        + "\","
        + "\""
        + "message"
        + "\":\""
        + ((cause != null) ? MarshallUtil.jsonStringEscape(cause.getClass().getName()) : "")
        + ((message != null) ? ":" + MarshallUtil.jsonStringEscape(message) : "")
        + "\"}";
  }
Ejemplo n.º 2
0
  @Override
  public String marshall(final T o, final MarshallingSession ctx) {
    final StringBuilder buf = new StringBuilder();
    buf.append("{");
    int i = 0;
    for (final Map.Entry<Object, Object> entry : o.entrySet()) {
      if (i++ > 0) {
        buf.append(",");
      }

      final Marshaller<Object> keyMarshaller;
      final Marshaller<Object> valueMarshaller;
      if (entry.getKey() instanceof String) {
        buf.append("\"").append(entry.getKey()).append("\"");
      } else if (entry.getKey() != null) {
        if ((entry.getKey() instanceof Number
                && !(entry.getKey() instanceof BigInteger || entry.getKey() instanceof BigDecimal))
            || entry.getKey() instanceof Boolean
            || entry.getKey() instanceof Character) {
          keyMarshaller = MarshallUtil.getQualifiedNumberMarshaller(entry.getKey());
        } else {
          keyMarshaller = MarshallUtil.getMarshaller(entry.getKey(), ctx);
        }

        buf.append(("\"" + SerializationParts.EMBEDDED_JSON))
            .append(
                MarshallUtil.jsonStringEscape(
                    keyMarshaller.marshall(MarshallUtil.maybeUnwrap(entry.getKey()), ctx)))
            .append("\"");
      } else {
        buf.append("\"" + SerializationParts.NULL_VALUE + "\"");
      }

      buf.append(":");

      if (entry.getValue() == null) {
        buf.append("null");
      } else {
        if ((entry.getValue() instanceof Number
                && !(entry.getValue() instanceof BigInteger
                    || entry.getValue() instanceof BigDecimal))
            || entry.getValue() instanceof Boolean
            || entry.getValue() instanceof Character) {

          valueMarshaller = MarshallUtil.getQualifiedNumberMarshaller(entry.getValue());
        } else {
          valueMarshaller = MarshallUtil.getMarshaller(entry.getValue(), ctx);
        }
        buf.append(valueMarshaller.marshall(MarshallUtil.maybeUnwrap(entry.getValue()), ctx));
      }
    }

    return buf.append("}").toString();
  }
Ejemplo n.º 3
0
 @Override
 public Marshaller<Object> getMarshallerInstance(final String fqcn) {
   Marshaller<Object> marshaller = context.getMarshaller(fqcn);
   if (marshaller == null) {
     if (fqcn == null) {
       return NULL_MARSHALLER;
     }
     if (fqcn.startsWith("[")) {
       marshaller = context.getMarshaller(MarshallUtil.getComponentClassName(fqcn));
       if (marshaller != null) {
         marshaller = new ArrayMarshallerWrapper(marshaller);
       }
     }
   }
   return marshaller;
 }