Java Code Examples for org.nustaq.serialization.FSTConfiguration#asObject()

The following examples show how to use org.nustaq.serialization.FSTConfiguration#asObject() . 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: FstExample.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();

    SomeMediumClass mediumClass = new SomeMediumClass();
    byte barray[] = conf.asByteArray(mediumClass);
    System.out.println(barray.length);
    SomeMediumClass object = (SomeMediumClass)conf.asObject(barray);
    System.out.println(object);


    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    FSTObjectOutput output = new FSTObjectOutput(outputStream);
    output.writeObject(mediumClass);
    output.close();

    FSTObjectInput input = new FSTObjectInput(new ByteArrayInputStream(outputStream.toByteArray()));
    object = (SomeMediumClass)input.readObject(SomeMediumClass.class);
    System.out.println(object);
}
 
Example 2
Source File: Serializer.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
public static <T> T asObject(byte[] b, Class<T> clazz) {
  FSTConfiguration fst = getFST();
  Object obj = fst.asObject(b);
  if (isNull(obj)) {
    return null;
  }
  return clazz.cast(obj);
}
 
Example 3
Source File: FSTJsonSerializer.java    From Thunder with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T fromJson(FSTConfiguration fst, String json, Class<T> clazz) {
    if (StringUtils.isEmpty(json)) {
        throw new SerializerException("Json is null or empty");
    }

    return (T) fst.asObject(json.getBytes());
}
 
Example 4
Source File: FSTSerializer.java    From Thunder with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T deserialize(FSTConfiguration fst, byte[] bytes) {
    if (ArrayUtils.isEmpty(bytes)) {
        throw new SerializerException("Bytes is null or empty");
    }

    return (T) fst.asObject(bytes);
}
 
Example 5
Source File: TemporalMemoryTest.java    From htm.java with GNU Affero General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> T deepCopyPlain(T t) {
    FSTConfiguration fastSerialConfig = FSTConfiguration.createDefaultConfiguration();
    byte[] bytes = fastSerialConfig.asByteArray(t);
    return (T)fastSerialConfig.asObject(bytes);
}