com.backendless.utils.JSONConverterWeborbImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-sdk-common Show documentation
Show all versions of java-sdk-common Show documentation
Provides access to Backendless API
The newest version!
package com.backendless.utils;
import com.backendless.util.JSONConverter;
import weborb.exceptions.AdaptingException;
import weborb.types.IAdaptingType;
import weborb.util.io.ISerializer;
import weborb.util.io.Serializer;
import java.io.IOException;
import java.lang.reflect.Type;
public class JSONConverterWeborbImpl implements JSONConverter
{
@Override
public T readObject( String jsonString, Type type )
{
try
{
IAdaptingType adaptingType = (IAdaptingType) Serializer.fromBytes( jsonString.getBytes(), Serializer.JSON, true );
return (T) adaptingType.adapt( type );
}
catch( IOException e )
{
throw new IllegalStateException( e );
}
catch( AdaptingException e )
{
throw new RuntimeException( e );
}
}
@Override
public String writeObject( Object obj )
{
try
{
byte[] bytes = Serializer.toBytes( obj, ISerializer.JSON );
return new String( bytes );
}
catch( Exception e )
{
throw new IllegalStateException( e );
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy