Package com.cedarsoft.version

Examples of com.cedarsoft.version.Version


    //So it seems easier to add just one if/else.
    //If a serializer evolves further a switch to the strategy pattern might be done. A simple map holding the strategies should do it.


    //The common case - current version
    if ( formatVersion.equals( new Version( 1, 0, 1 ) ) ) {
      int cents = Integer.parseInt( deserializeFrom.getAttributeValue( null, "cents" ) );

      //We have to close the tag! Every stax based serializer has to close its tag
      //getText does this automatically for us. But when only using attributes, we have to close it manually.
      closeTag( deserializeFrom );

      return new Money( cents );

      //The old format that does not use an attribute but text instead
    } else if ( formatVersion.equals( new Version( 1, 0, 0 ) ) ) {
      int cents = Integer.parseInt( getText( deserializeFrom ) );

      //We don't have to close the tag. The getText method does that for us
      return new Money( cents );
View Full Code Here


  @Override
  @Nonnull
  public T deserialize( @Nonnull JsonParser parser ) throws IOException, JsonProcessingException, InvalidTypeException {
    JacksonParserWrapper wrapper = new JacksonParserWrapper( parser );

    Version version;
    if ( isObjectType() ) {
      wrapper.nextToken( JsonToken.START_OBJECT );

      wrapper.nextFieldValue( PROPERTY_TYPE );
      String readNs = parser.getText();
View Full Code Here

    serializeArray( elements, type, null, serializeTo, formatVersion );
  }

  protected <T> void serializeArray( @Nonnull Iterable<? extends T> elements, @Nonnull Class<T> type, @Nullable String propertyName, @Nonnull JsonGenerator serializeTo, @Nonnull Version formatVersion ) throws IOException {
    JacksonSerializer<? super T> serializer = getSerializer( type );
    Version delegateVersion = delegatesMappings.getVersionMappings().resolveVersion( type, formatVersion );

    if ( propertyName == null ) {
      serializeTo.writeStartArray();
    } else {
      serializeTo.writeArrayFieldStart( propertyName );
View Full Code Here

      serializeTo.writeNull();
      return;
    }

    JacksonSerializer<? super T> serializer = getSerializer( type );
    Version delegateVersion = delegatesMappings.getVersionMappings().resolveVersion( type, formatVersion );
    if ( serializer.isObjectType() ) {
      serializeTo.writeStartObject();
    }

    serializer.serialize( serializeTo, object, delegateVersion );
View Full Code Here

    if ( !PROPERTY_MIN.equals( currentName3 ) ) {
      throw new JsonParseException( "Invalid field. Expected <" + PROPERTY_MIN + "> but was <" + currentName3 + ">", parserWrapper.getCurrentLocation() );
    }
    parserWrapper.nextToken();
    Version min = Version.parse( deserializeFrom.getText() );
    //max
    parserWrapper.nextToken();
    parserWrapper.verifyCurrentToken( JsonToken.FIELD_NAME );
    String currentName2 = parserWrapper.getCurrentName();

    if ( !PROPERTY_MAX.equals( currentName2 ) ) {
      throw new JsonParseException( "Invalid field. Expected <" + PROPERTY_MAX + "> but was <" + currentName2 + ">", parserWrapper.getCurrentLocation() );
    }
    parserWrapper.nextToken();
    Version max = Version.parse( deserializeFrom.getText() );
    //includeLower
    parserWrapper.nextToken();
    parserWrapper.verifyCurrentToken( JsonToken.FIELD_NAME );
    String currentName1 = parserWrapper.getCurrentName();
View Full Code Here

/**
*
*/
public class DateTimeSerializer extends AbstractJacksonSerializer<DateTime> {
  public DateTimeSerializer() {
    super( "dateTime", new VersionRange( new Version( 0, 9, 0 ), new Version( 1, 0, 0 ) ) );
  }
View Full Code Here

      throw new JsonParseException( "Invalid field. Expected <" + PROPERTY_NAME + "> but was <" + currentName + ">", parserWrapper.getCurrentLocation() );
    }
    parserWrapper.nextToken();
    String name = parserWrapper.getText();
    //version
    Version version = deserialize( Version.class, PROPERTY_VERSION, formatVersion, deserializeFrom );
    //Finally closing element
    parserWrapper.nextToken( JsonToken.END_OBJECT );
    //Constructing the deserialized object
    return new Application( name, version );
  }
View Full Code Here

    //Type and Version
    nextFieldValue( parser, AbstractJacksonSerializer.PROPERTY_TYPE );
    wrappedSerializer.verifyType( parser.getText() );
    nextFieldValue( parser, AbstractJacksonSerializer.PROPERTY_VERSION );
    Version version = Version.parse( parser.getText() );

    //The wrapped object
    T wrapped = wrappedSerializer.deserialize( parser, version );

    //the attachments - if there are any....
View Full Code Here

  public Version parseAndVerifyNameSpace( @Nullable String namespaceURI ) throws InvalidNamespaceException, VersionException {
    //Verify the name space
    verifyNamespace( namespaceURI );

    //Parse and verify the version
    Version formatVersion = parseVersionFromNamespace( namespaceURI );
    verifyVersionReadable( formatVersion );
    return formatVersion;
  }
View Full Code Here

   */
  @Theory
  public void testVersion( @Nonnull VersionEntry entry ) throws Exception {
    Serializer<T> serializer = getSerializer();

    Version version = entry.getVersion();
    byte[] serialized = entry.getSerialized( serializer );

    T deserialized = serializer.deserialize( new ByteArrayInputStream( serialized ) );
    verifyDeserialized( deserialized, version );
  }
View Full Code Here

TOP

Related Classes of com.cedarsoft.version.Version

Copyright © 2018 www.massapicom. 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.