org.apache.commons.lang.SerializationException Java Examples

The following examples show how to use org.apache.commons.lang.SerializationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MemcachedClientTest.java    From ob1k with Apache License 2.0 6 votes vote down vote up
@Test(expected = ExecutionException.class)
public void testMultiget_TranscoderExecption() throws ExecutionException, InterruptedException, TimeoutException {
  final Transcoder<Serializable> transcoder = new Transcoder<Serializable>() {
    @Override
    public Serializable decode(final byte[] b) {
      throw new SerializationException("QQQQQ YYYYY");
    }

    @Override
    public byte[] encode(final Serializable t) {
      return SerializationUtils.serialize(t);
    }
  };

  final MemcachedClient<Object, Serializable> client = createClient(transcoder);

  client.setAsync("meh", "its here").get();
  client.getBulkAsync(Lists.newArrayList("meh", "bah")).get(1, TimeUnit.MINUTES);
}
 
Example #2
Source File: ProtobufMsgFactory.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T extends Message> T getDefaultInstance(final String className) {
    final MethodHandle handle = DEFAULT_INSTANCE_METHODS_4J.get(className);
    if (handle == null) {
        throw new MessageClassNotFoundException(className + " not found");
    }
    try {
        return (T) handle.invoke();
    } catch (Throwable t) {
        throw new SerializationException(t);
    }
}
 
Example #3
Source File: ProtobufMsgFactory.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T extends Message> T newMessageByJavaClassName(final String className, final byte[] bs) {
    final MethodHandle handle = PARSE_METHODS_4J.get(className);
    if (handle == null) {
        throw new MessageClassNotFoundException(className + " not found");
    }
    try {
        return (T) handle.invoke(bs);
    } catch (Throwable t) {
        throw new SerializationException(t);
    }
}
 
Example #4
Source File: ProtobufMsgFactory.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T extends Message> T newMessageByProtoClassName(final String className, final byte[] bs) {
    final MethodHandle handle = PARSE_METHODS_4PROTO.get(className);
    if (handle == null) {
        throw new MessageClassNotFoundException(className + " not found");
    }
    try {
        return (T) handle.invoke(bs);
    } catch (Throwable t) {
        throw new SerializationException(t);
    }
}
 
Example #5
Source File: MessagePackTranscoder.java    From ob1k with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public T decode(final byte[] b) {
  final Template<?> template = messagePack.lookup(valueType);

  try {
    final Value value = messagePack.read(b);
    return (T) template.read(new Converter(messagePack, value), null);
  } catch (final IOException e) {
    throw new SerializationException("Failed to decode to type " + valueType.getTypeName(), e);
  }
}
 
Example #6
Source File: MessagePackTranscoder.java    From ob1k with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] encode(final T t) {
  try {
    return messagePack.write(t);
  } catch (final IOException e) {
    throw new SerializationException("Failed to encode input " + t.getClass().getSimpleName() + " to type " + valueType.getTypeName(), e);
  }
}
 
Example #7
Source File: JsonTranscoder.java    From ob1k with Apache License 2.0 5 votes vote down vote up
@Override
public T decode(final byte[] b) {
  try {
    return objectMapper.readValue(b, valueType);
  } catch (final IOException e) {
    throw new SerializationException("Failed to decode to type " + valueType.getSimpleName(), e);
  }
}
 
Example #8
Source File: JsonTranscoder.java    From ob1k with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] encode(final T t) {
  try {
    return objectMapper.writeValueAsBytes(t);
  } catch (final JsonProcessingException e) {
    throw new SerializationException("Failed to encode input " + t.getClass().getSimpleName() + " to type " + valueType.getSimpleName(), e);
  }
}
 
Example #9
Source File: MoreoverXmlActivitySerializer.java    From streams with Apache License 2.0 5 votes vote down vote up
private Article deserializeMoreover(String serialized) {
  try {
    Unmarshaller unmarshaller = articleContext.createUnmarshaller();
    return (Article) unmarshaller.unmarshal(new StringReader(serialized));
  } catch (JAXBException ex) {
    throw new SerializationException("Unable to deserialize Moreover data", ex);
  }
}
 
Example #10
Source File: MoreoverXmlActivitySerializer.java    From streams with Apache License 2.0 5 votes vote down vote up
private ArticlesResponse deserializeMoreoverResponse(String serialized) {
  try {
    Unmarshaller unmarshaller = articlesContext.createUnmarshaller();
    return ((JAXBElement<ArticlesResponse>) unmarshaller.unmarshal(new StringReader(serialized))).getValue();
  } catch (JAXBException ex) {
    throw new SerializationException("Unable to deserialize Moreover data", ex);
  }
}
 
Example #11
Source File: DefaultExceptionCodec.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<Throwable> fromBytes(final byte[] bytes) {
  try {
    if (bytes != null && bytes.length > 0) {
      return Optional.of((Throwable) SerializationUtils.deserialize(bytes));
    }
  } catch (final SerializationException | IllegalArgumentException e) {
    LOG.log(Level.WARNING, "Unable to deserialize a Throwable.", e);
  }
  return Optional.empty();
}
 
Example #12
Source File: JaxBDeserializer.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a JAX-WS deserializer for the specified class.
 *
 * @param clazz Class to deserialize.
 * @throws SerializationException if unable to construct the deserializer.
 */
public JaxBDeserializer(Class<T> clazz) {
  this.clazz = clazz;
  try {
    this.jaxbContext = JAXBContext.newInstance(clazz);
  } catch (JAXBException e) {
    throw new SerializationException(
        String.format("Could not construct deserializer for class: %s.", clazz), e);
  }
}
 
Example #13
Source File: JaxBDeserializer.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Deserializes the object.
 *
 * @throws SerializationException if we cannot deserialize the object.
 */
public T deserialize(Source source) {
  try {
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    JAXBElement<T> jaxbElement = unmarshaller.unmarshal(source, clazz);
    return jaxbElement.getValue();
  } catch (JAXBException e) {
    throw new SerializationException(
        String.format("Could not deserialize %s object from source %s.", clazz, source), e);
  }
}
 
Example #14
Source File: JaxBSerializer.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a JAX-WS serializer for the specified class.
 *
 * @param clazz Class to serialize.
 * @param qname A QName representing the local name for the class - this will be used as the root
 *        tag name.
 * @throws SerializationException if unable to construct the serializer.
 */
public JaxBSerializer(Class<T> clazz, QName qname) {
  this.clazz = clazz;
  this.qname = qname;
  try {
    this.jaxbContext = JAXBContext.newInstance(clazz);
  } catch (JAXBException e) {
    throw new SerializationException(
        String.format(
            "Could not construct a serializer for class %s and QName %s.", clazz, qname),
        e);
  }
}
 
Example #15
Source File: JaxBSerializer.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Serializes the object with the option to include or exclude the XML declaration.
 *
 * @throws SerializationException if we cannot serialize the object.
 */
public String serialize(T object, boolean includeXmlDeclaration) {
  try {
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.valueOf(!includeXmlDeclaration));
    JAXBElement<T> element =
        new JAXBElement<T>(qname, clazz, object);
    StringWriter stringWriter = new StringWriter();
    marshaller.marshal(element, stringWriter);
    return stringWriter.toString();
  } catch (JAXBException e) {
    throw new SerializationException(String.format("Could not serialize object: %s.", object), e);
  }
}