com.backendless.hive.HiveSerializer 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.hive;
import com.backendless.utils.WeborbSerializationHelper;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
final class HiveSerializer
{
static String serialize( Object obj )
{
return new String( WeborbSerializationHelper.serialize( obj ), StandardCharsets.UTF_8 );
}
static T deserialize( String jsonString )
{
return (T) WeborbSerializationHelper.deserialize( jsonString.getBytes( StandardCharsets.UTF_8 ) );
}
static HashMap serializeAsMap( Map mapOfObjects )
{
HashMap result = new HashMap<>();
for( Map.Entry entry : mapOfObjects.entrySet() )
{
if( entry.getValue() == null )
throw new IllegalArgumentException( "null value for key '" + entry.getKey() + "'" );
result.put( entry.getKey(), serialize( entry.getValue() ) );
}
return result;
}
static HashMap deserialize( Map mapOfJsonStrings )
{
HashMap result = new HashMap<>();
for( Map.Entry entry : mapOfJsonStrings.entrySet() )
result.put( entry.getKey(), deserialize( entry.getValue() ) );
return result;
}
static ArrayList serializeAsList( Collection> listOfObjects )
{
ArrayList result = new ArrayList<>();
for( Object obj : listOfObjects )
{
if( obj == null )
throw new IllegalArgumentException( "null value found in collection" );
result.add( serialize( obj ) );
}
return result;
}
static ArrayList deserializeAsList( String[] arrayOfJsonStrings )
{
ArrayList result = new ArrayList<>();
for( String listOfJsonString : arrayOfJsonStrings )
result.add( deserialize( listOfJsonString ) );
return result;
}
static HashSet deserializeAsSet( String[] listOfJsonStrings )
{
HashSet result = new HashSet<>();
for( String listOfJsonString : listOfJsonStrings )
result.add( deserialize( listOfJsonString ) );
return result;
}
static LinkedHashSet deserializeAsLinkedSet( String[] listOfJsonStrings )
{
LinkedHashSet result = new LinkedHashSet<>();
for( String listOfJsonString : listOfJsonStrings )
result.add( deserialize( listOfJsonString ) );
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy