Examples of JacksonParserWrapper


Examples of com.cedarsoft.serialization.jackson.JacksonParserWrapper

    return deserialized;
  }

  @Nonnull
  public UniqueId deserialize( @Nonnull JsonParser deserializeFrom ) throws VersionException, IOException {
    JacksonParserWrapper parser = new JacksonParserWrapper( deserializeFrom );

    String id = null;
    String rev = null;

    while ( parser.nextToken() == JsonToken.FIELD_NAME ) {
      String currentName = parser.getCurrentName();

      if ( currentName.equals( PROPERTY_OK ) ) {
        parser.nextToken( JsonToken.VALUE_TRUE );
        //we don't need that value
        continue;
      }

      if ( currentName.equals( PROPERTY_ID ) ) {
        parser.nextToken( JsonToken.VALUE_STRING );
        id = deserializeFrom.getText();
        continue;
      }

      if ( currentName.equals( PROPERTY_REV ) ) {
        parser.nextToken( JsonToken.VALUE_STRING );
        rev = deserializeFrom.getText();
        continue;
      }

      throw new IllegalStateException( "Unexpected field reached <" + currentName + ">" );
    }

    parser.verifyDeserialized( id, PROPERTY_ID );
    parser.verifyDeserialized( rev, PROPERTY_REV );
    assert rev != null;
    assert id != null;

    parser.ensureObjectClosed();

    return new UniqueId( new DocId( id ), new Revision( rev ) );

    //    AbstractJacksonSerializer.nextToken( deserializeFrom, JsonToken.FIELD_NAME );
    //    if ( deserializeFrom.getCurrentName().equals( PROPERTY_OK ) ) {
View Full Code Here

Examples of com.cedarsoft.serialization.jackson.JacksonParserWrapper

  @Nonnull
  public <T> CouchDoc<T> deserialize( @Nonnull JacksonSerializer<T> wrappedSerializer, @WillClose @Nonnull InputStream in ) {
    try {
      try {
        JsonParser parser = RawCouchDocSerializer.createJsonParser( in );
        JacksonParserWrapper parserWrapper = new JacksonParserWrapper( parser );
        CouchDoc<T> doc = deserialize( wrappedSerializer, parserWrapper );

        parserWrapper.ensureParserClosed();
        return doc;
      } finally {
        in.close();
      }
    } catch ( InvalidTypeException | IOException e ) {
View Full Code Here

Examples of com.cedarsoft.serialization.jackson.JacksonParserWrapper

  @Nonnull
  public <K, V, D> Row<K, V, D> deserialize( @Nonnull JacksonSerializer<? super K> keySerializer, @Nonnull JacksonSerializer<? super V> valueSerializer, @Nullable JacksonSerializer<? extends D> documentSerializer, @Nonnull InputStream in ) throws IOException, InvalidTypeException {
    JsonFactory jsonFactory = JacksonSupport.getJsonFactory();

    JsonParser parser = jsonFactory.createJsonParser( in );
    JacksonParserWrapper parserWrapper = new JacksonParserWrapper( parser );
    parserWrapper.nextToken( JsonToken.START_OBJECT );

    return deserialize( keySerializer, valueSerializer, documentSerializer, parser );
  }
View Full Code Here

Examples of com.cedarsoft.serialization.jackson.JacksonParserWrapper

    return deserialize( keySerializer, valueSerializer, null, parser );
  }

  @Nonnull
  public <K, V, D> Row<K, V, D> deserialize( @Nonnull JacksonSerializer<? super K> keySerializer, @Nonnull JacksonSerializer<? super V> valueSerializer, @Nullable JacksonSerializer<? extends D> documentSerializer, @Nonnull JsonParser parser ) throws IOException, InvalidTypeException {
    JacksonParserWrapper wrapper = new JacksonParserWrapper( parser );
    wrapper.nextToken( JsonToken.FIELD_NAME );
    String fieldName = wrapper.getCurrentName();

    //The id
    @Nullable final DocId id;
    if ( fieldName.equals( PROPERTY_ID ) ) {
      wrapper.nextValue();
      id = new DocId( wrapper.getText() );
      wrapper.nextField( PROPERTY_KEY );
    }else {
      id = null;
    }

    //The key
    K key = ( K ) keySerializer.deserialize( parser );

    //The value
    wrapper.nextField( PROPERTY_VALUE );

    @Nullable
    V value = ( V ) valueSerializer.deserialize( parser );

    //The doc - if available
    @Nullable
    CouchDoc<? extends D> doc;

    JsonToken nextToken = wrapper.nextToken();
    if ( nextToken == JsonToken.FIELD_NAME ) {
      if ( documentSerializer == null ) {
        throw new NullPointerException( "No document serializer found" );
      }
      doc = couchDocSerializer.deserialize( documentSerializer, new JacksonParserWrapper( parser ) );

      wrapper.closeObject();
    } else {
      doc = null;
    }

    wrapper.verifyCurrentToken( JsonToken.END_OBJECT );
    return new Row<>( id, key, value, doc );
  }
View Full Code Here

Examples of com.cedarsoft.serialization.jackson.JacksonParserWrapper

    try ( MaxLengthByteArrayOutputStream teedOut = new MaxLengthByteArrayOutputStream(); TeeInputStream teeInputStream = new TeeInputStream( in, teedOut ) ) {

      JsonFactory jsonFactory = JacksonSupport.getJsonFactory();

      JsonParser parser = jsonFactory.createJsonParser( teeInputStream );
      JacksonParserWrapper parserWrapper = new JacksonParserWrapper( parser );

      parserWrapper.nextTokenJsonToken.START_OBJECT );


      String error = null;
      String reason = null;

      while ( parser.nextToken() == JsonToken.FIELD_NAME ) {
        String currentName = parser.getCurrentName();

        if ( currentName.equals( PROPERTY_ERROR ) ) {
          parserWrapper.nextToken( JsonToken.VALUE_STRING );
          error = parser.getText();
          continue;
        }

        if ( currentName.equals( PROPERTY_REASON ) ) {
          parserWrapper.nextToken( JsonToken.VALUE_STRING );
          reason = parser.getText();
          continue;
        }

        throw new IllegalStateException( "Unexpected field reached <" + currentName + ">" );
      }

      parserWrapper.verifyDeserialized( error, PROPERTY_ERROR );
      parserWrapper.verifyDeserialized( reason, PROPERTY_REASON );
      assert reason != null;
      assert error != null;

      parserWrapper.ensureObjectClosed();

      return new ActionFailedException( status, error, reason, teedOut.toByteArray() );
    }
  }
View Full Code Here

Examples of com.cedarsoft.serialization.jackson.JacksonParserWrapper

  @Nonnull
  public RawCouchDoc deserialize( @Nonnull InputStream in ) throws IOException {
    JsonParser parser = createJsonParser( in );
    RawCouchDoc doc = deserialize( parser );

    JacksonParserWrapper parserWrapper = new JacksonParserWrapper( parser );
    parserWrapper.ensureParserClosed();
    return doc;
  }
View Full Code Here

Examples of com.cedarsoft.serialization.jackson.JacksonParserWrapper

    return doc;
  }

  @Nonnull
  public RawCouchDoc deserialize( @Nonnull JsonParser parser ) throws IOException {
    JacksonParserWrapper parserWrapper = new JacksonParserWrapper( parser );
    parserWrapper.nextToken( JsonToken.START_OBJECT );

    parserWrapper.nextFieldValue( PROPERTY_ID );
    String id = parser.getText();

    parserWrapper.nextFieldValue( PROPERTY_REV );
    String rev = parser.getText();

    parser.nextToken();

    parserWrapper.ensureObjectClosed();
    return new RawCouchDoc( new DocId( id ), new Revision( rev ) );
  }
View Full Code Here

Examples of com.cedarsoft.serialization.jackson.JacksonParserWrapper

  public <K, V, D> ViewResponse<K, V, D> deserialize( @Nonnull JacksonSerializer<? super K> keySerializer, @Nonnull JacksonSerializer<? super V> valueSerializer, @Nullable JacksonSerializer<? extends D> documentSerializer, @Nonnull InputStream in ) throws IOException, InvalidTypeException {
    JsonFactory jsonFactory = JacksonSupport.getJsonFactory();
    JsonParser parser = jsonFactory.createJsonParser( in );

    JacksonParserWrapper parserWrapper = new JacksonParserWrapper( parser );
    parserWrapper.nextTokenJsonToken.START_OBJECT );


    parserWrapper.nextTokenJsonToken.FIELD_NAME );
    //If reduced, no total rows and no offset are availlable!

    String fieldName = parser.getText();

    int totalRows = -1;
    int offset = -1;
    while ( !fieldName.equals( PROPERTY_ROWS ) ) {
      if ( fieldName.equals( PROPERTY_TOTAL_ROWS ) ) {
        parserWrapper.nextToken( JsonToken.VALUE_NUMBER_INT );
        totalRows = parser.getIntValue();
      }

      if ( fieldName.equals( PROPERTY_OFFSET ) ) {
        parserWrapper.nextToken( JsonToken.VALUE_NUMBER_INT );
        offset = parser.getIntValue();
      }

      parserWrapper.nextToken( JsonToken.FIELD_NAME );
      fieldName = parser.getText();
    }

    //Now the rows...
    parserWrapper.nextToken( JsonToken.START_ARRAY );

    List<Row<K, V, D>> deserialized = new ArrayList<>();
    while ( parser.nextToken() != JsonToken.END_ARRAY ) {
      Row<K, V, D> deserializedRow = rowSerializer.deserialize( keySerializer, valueSerializer, documentSerializer, parser );
      deserialized.add( deserializedRow );
View Full Code Here

Examples of com.cedarsoft.serialization.jackson.JacksonParserWrapper

      }

      JsonFactory jsonFactory = JacksonSupport.getJsonFactory();
      try ( InputStream entityInputStream = response.getEntityInputStream() ) {
        JsonParser parser = jsonFactory.createJsonParser( entityInputStream );
        JacksonParserWrapper wrapper = new JacksonParserWrapper( parser );

        wrapper.nextToken( JsonToken.START_OBJECT );

        wrapper.nextFieldValue( "_id" );
        wrapper.nextFieldValue( "_rev" );
        return new Revision( wrapper.getText() );
      }
    } finally {
      response.close();
    }
  }
View Full Code Here

Examples of com.cedarsoft.serialization.jackson.JacksonParserWrapper

  @Nonnull
  @Override
  public DesignDocumentsVersionInfo deserialize( @Nonnull JsonParser deserializeFrom, @Nonnull Version formatVersion ) throws VersionException, IOException, JsonProcessingException {
    verifyVersionReadable( formatVersion );
    JacksonParserWrapper parser = new JacksonParserWrapper( deserializeFrom );

    long updatedAt=-1;
    Version version = null;
    String updatedBy = null;

    while ( parser.nextToken() == JsonToken.FIELD_NAME ) {
      String currentName = parser.getCurrentName();

      if ( currentName.equals( PROPERTY_DOCS_VERSION ) ) {
        parser.nextToken( JsonToken.VALUE_STRING );
        version = Version.parse( deserializeFrom.getText() );
        continue;
      }

      if ( currentName.equals( PROPERTY_UPDATEDAT ) ) {
        parser.nextToken( JsonToken.VALUE_NUMBER_INT );
        updatedAt = deserializeFrom.getLongValue();
        continue;
      }

      if ( currentName.equals( PROPERTY_UPDATEDBY ) ) {
        parser.nextToken( JsonToken.VALUE_STRING );
        updatedBy = deserializeFrom.getText();
        continue;
      }

      throw new IllegalStateException( "Unexpected field reached <" + currentName + ">" );
    }

    parser.verifyDeserialized( version, PROPERTY_VERSION );
    parser.verifyDeserialized( updatedBy, PROPERTY_UPDATEDBY );
    parser.verifyDeserialized( updatedAt, PROPERTY_UPDATEDAT );

    assert updatedBy != null;
    assert version != null;

    parser.ensureObjectClosed();

    //Finally closing element
    parser.ensureObjectClosed();
    //Constructing the deserialized object
    return new DesignDocumentsVersionInfo( version, updatedAt, updatedBy );
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.