PrettySerializer extends Serializer { @Nonnull @Override @SuppressWarnings("unchecked") public <Message extends PMessage<Message, Field>, Field extends PField> PServiceCall<Message, Field> deserialize(@Nonnull InputStream input, @Nonnull PService service) throws IOException { String methodName = null; int sequence = 0; PServiceCallType callType = null; try { Tokenizer tokenizer = new Tokenizer(input); Token token = tokenizer.expect("Sequence or type"); if (token.isInteger()) { sequence = (int) token.parseInteger(); tokenizer.expectSymbol("Sequence type sep", Token.kKeyValueSep); token = tokenizer.expectIdentifier("Call Type"); } callType = PServiceCallType.findByName(token.asString().toUpperCase(Locale.US)); if (callType == null) { throw new TokenizerException(token, "No such call type %s", token.asString()) .setLine(tokenizer.getLine()) .setExceptionType(PApplicationExceptionType.INVALID_MESSAGE_TYPE); } token = tokenizer.expectIdentifier("method name"); methodName = token.asString(); PServiceMethod method = service.getMethod(methodName); if (method == null) { throw new TokenizerException(token, "no such method %s on service %s", methodName, service.getQualifiedName()) .setLine(tokenizer.getLine()) .setExceptionType(PApplicationExceptionType.UNKNOWN_METHOD); } tokenizer.expectSymbol("call params start", Token.kParamsStart); Message message; switch (callType) { case CALL: case ONEWAY: message = (Message) readMessage(tokenizer, method.getRequestType(), true); break; case REPLY: message = (Message) readMessage(tokenizer, method.getResponseType(), true); break; case EXCEPTION: message = (Message) readMessage(tokenizer, PApplicationException.kDescriptor, true); break; default: throw new IllegalStateException("Unreachable code reached"); } return new PServiceCall<>(methodName, callType, sequence, message); } catch (TokenizerException e) { e.setCallType(callType) .setSequenceNo(sequence) .setMethodName(methodName); throw e; } catch (IOException e) { throw new SerializerException(e, e.getMessage()) .setCallType(callType) .setSequenceNo(sequence) .setMethodName(methodName); } } PrettySerializer();  PrettySerializer(boolean strict); private  PrettySerializer(String indent,
                             String space,
                             String newline,
                             String entrySep,
                             boolean strict,
                             boolean prefixWithQualifiedName); PrettySerializer compact(); PrettySerializer string(); PrettySerializer config(); int serialize(@Nonnull OutputStream out, @Nonnull Message message); @Override int serialize(@Nonnull OutputStream out, @Nonnull PServiceCall<Message, Field> call); @Nonnull @Override @SuppressWarnings("unchecked") PServiceCall<Message, Field> deserialize(@Nonnull InputStream input, @Nonnull PService service); @Nonnull @Override Message deserialize(@Nonnull InputStream input,
                        @Nonnull PMessageDescriptor<Message, Field> descriptor); @Override boolean binaryProtocol(); @Nonnull @Override String mediaType(); final static String MEDIA_TYPE; }
@Test public void testParse() throws IOException { PrettySerializer serializer = new PrettySerializer(); Operation actual = serializer.deserialize(getClass().getResourceAsStream("/json/calculator/pretty.cfg"), Operation.kDescriptor); assertEquals(mOperation, actual); }