Skip to content

Commit

Permalink
Fix #509 (add IonValueMapper.builder() overloads)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 15, 2024
1 parent 294051d commit b5a57eb
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import com.fasterxml.jackson.dataformat.ion.EnumAsIonSymbolModule;
import com.fasterxml.jackson.dataformat.ion.IonFactory;
import com.fasterxml.jackson.dataformat.ion.IonObjectMapper;

import com.amazon.ion.IonSystem;
import com.amazon.ion.IonValue;
import com.amazon.ion.system.IonSystemBuilder;

/**
* Supports serializing Ion to POJO and back using the Jackson Ion framework.
Expand Down Expand Up @@ -52,11 +52,27 @@ public IonValueMapper(IonSystem ionSystem) {
this(ionSystem, null);
}

// @since 2.18: needed for `copy()`
/**
* Needed for `copy()`
*
* @since 2.18
*/
protected IonValueMapper(IonValueMapper src) {
super(src);
}

/**
* Needed for some builders
*
* @since 2.18
*/
protected IonValueMapper(IonFactory f, PropertyNamingStrategy strategy) {
super(f);
this.registerModule(new IonValueModule());
this.registerModule(new EnumAsIonSymbolModule());
this.setPropertyNamingStrategy(strategy);
}

/**
* Constructor that provides an override on the default Constructor for the PropertyNamingStrategy.
*
Expand All @@ -66,19 +82,61 @@ protected IonValueMapper(IonValueMapper src) {
* {@link PropertyNamingStrategy}
*/
public IonValueMapper(IonSystem ionSystem, PropertyNamingStrategy strategy) {
super(new IonFactory(null, ionSystem));
this.registerModule(new IonValueModule());
this.registerModule(new EnumAsIonSymbolModule());
this.setPropertyNamingStrategy(strategy);
this(new IonFactory(null, ionSystem), strategy);
}

/*
/**********************************************************************
/* Life-cycle, builders
/*
/* NOTE: must "override" (mask) all static methods from parent class
/* (most of which just call basic `builder()` or `builder(IonSystem)`
/**********************************************************************
*/

// TODO: add overrides
public static Builder builder() {
return builder(IonSystemBuilder.standard().build());
}

public static Builder builder(IonSystem ionSystem) {
return builder(ionSystem, null);
}

/**
* Canonical {@code builder()} method that most other methods
* ultimately call.
*/
public static Builder builder(IonSystem ionSystem, PropertyNamingStrategy strategy) {
return new Builder(new IonValueMapper(ionSystem, strategy));
}

public static Builder builderForBinaryWriters() {
return builderForBinaryWriters(IonSystemBuilder.standard().build());
}

public static Builder builderForBinaryWriters(IonSystem ionSystem) {
return builder(IonFactory.builderForBinaryWriters()
.ionSystem(ionSystem)
.build());
}

public static Builder builderForTextualWriters() {
return builderForTextualWriters(IonSystemBuilder.standard().build());
}

public static Builder builderForTextualWriters(IonSystem ionSystem) {
return builder(IonFactory.builderForTextualWriters()
.ionSystem(ionSystem)
.build());
}

public static Builder builder(IonFactory streamFactory) {
return builder(streamFactory, null);
}

public static Builder builder(IonFactory streamFactory, PropertyNamingStrategy strategy) {
return new Builder(new IonValueMapper(streamFactory, strategy));
}

/*
/**********************************************************************
Expand Down
4 changes: 4 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,7 @@ Joachim Lous (@jlous)
* Requested #494: Avro Schema generation: allow mapping Java Enum properties to
Avro String values
(2.18.0)

Robert Noack (@mr-robert)
* Reported #509: IonValueMapper.builder() not implemented, does not register modules
(2.18.0)
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Active maintainers:
(contributed by Michal F)
#508: (avro) Ignore `specificData` field on serialization
(contributed by @pjfanning)
#509: IonValueMapper.builder() not implemented, does not register modules
(reported by Robert N)

2.17.3 (not yet released)

Expand Down

0 comments on commit b5a57eb

Please sign in to comment.