public String serialize ( final Object serviceState ) throws InvalidStateException , CouldNotPerformException { String jsonStringRep ; if ( serviceState instanceof Message ) { try { jsonStringRep = jsonFormat . printToString ( ( Message ) serviceState ) ; } catch ( Exception ex ) { throw new CouldNotPerformException ( "Could not serialize service argument to string!" , ex ) ; } } else { throw new InvalidStateException ( "Service attribute Class[" + serviceState . getClass ( ) . getSimpleName ( ) + "] not a protobuf message!" ) ; } return jsonStringRep ; }
Serialize a serviceState which can be a proto message enumeration or a java primitive to string . If its a primitive toString is called while messages or enumerations will be serialized into JSon