Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions exonum-java-binding/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Moved all packages inside `com.exonum.binding` to `com.exonum.binding.core` package.
That was required to give each module a unique root package to prevent 'split-packages'
problem. The migration guide has a regexp to update the service automatically.
- Replaced redundant `TypeAdapterFactory` in 'common' module with a single
`CommonTypeAdapterFactory`. `BlockTypeAdapterFactory` is renamed to `CoreTypeAdapterFactory`.
`JsonSerializer#json` and `JsonSerializer#builder` register `CommonTypeAdapterFactory`
by default. `CoreTypeAdapterFactory` must be registered explicitly if needed. (#971)


### Fixed
- The default [`Transaction#info`][tx-info-07] implementation causing an error on `transaction`
Expand Down
2 changes: 1 addition & 1 deletion exonum-java-binding/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

<dependency>
<groupId>com.ryanharter.auto.value</groupId>
<artifactId>auto-value-gson-annotations</artifactId>
<artifactId>auto-value-gson-runtime</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.common.base.Preconditions.checkArgument;

import com.exonum.binding.common.serialization.json.CommonTypeAdapterFactory;
import com.google.auto.value.AutoValue;
import com.google.common.base.Strings;
import com.google.gson.Gson;
Expand Down Expand Up @@ -119,7 +120,7 @@ public boolean isSuccessful() {
/**
* Provides a Gson type adapter for this class.
*
* @see com.exonum.binding.common.serialization.json.TransactionResultAdapterFactory
* @see CommonTypeAdapterFactory
*/
public static TypeAdapter<TransactionResult> typeAdapter(Gson gson) {
return new AutoValue_TransactionResult.GsonTypeAdapter(gson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public abstract class ConsensusConfiguration {
/**
* Provides a Gson type adapter for this class.
*
* @see com.exonum.binding.common.serialization.json.StoredConfigurationAdapterFactory
* @see com.exonum.binding.common.serialization.json.CommonTypeAdapterFactory
*/
public static TypeAdapter<ConsensusConfiguration> typeAdapter(Gson gson) {
return new AutoValue_ConsensusConfiguration.GsonTypeAdapter(gson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public abstract class StoredConfiguration {
/**
* Provides a Gson type adapter for this class.
*
* @see com.exonum.binding.common.serialization.json.StoredConfigurationAdapterFactory
* @see com.exonum.binding.common.serialization.json.CommonTypeAdapterFactory
*/
public static TypeAdapter<StoredConfiguration> typeAdapter(Gson gson) {
return new AutoValue_StoredConfiguration.GsonTypeAdapter(gson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class ValidatorKey {
/**
* Provides a Gson type adapter for this class.
*
* @see com.exonum.binding.common.serialization.json.StoredConfigurationAdapterFactory
* @see com.exonum.binding.common.serialization.json.CommonTypeAdapterFactory
*/
public static TypeAdapter<ValidatorKey> typeAdapter(Gson gson) {
return new AutoValue_ValidatorKey.GsonTypeAdapter(gson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@
import com.ryanharter.auto.value.gson.GsonTypeAdapterFactory;

/**
* Class used to automatically create Gson type adapters for AutoValue classes.
* Note that you need to provide static factory method in your AutoValue class.
* Class used to automatically create Gson type adapters for all AutoValue classes
* located in this module.
*
* <p>Note that you need to provide an accessible static factory method in your AutoValue class.
*
* <pre><code>
* public static TypeAdapter&lt;TransactionResult&gt; typeAdapter(Gson gson) {
* return new AutoValue_TransactionResult.GsonTypeAdapter(gson);
* }
* </code></pre>
*
* @see <a href="https://github.com/rharter/auto-value-gson/#factory">
* Using TypeAdapterFactory</a>
*/
@GsonTypeAdapterFactory
public abstract class TransactionResultAdapterFactory implements TypeAdapterFactory {
public abstract class CommonTypeAdapterFactory implements TypeAdapterFactory {

public static TypeAdapterFactory create() {
return new AutoValueGson_TransactionResultAdapterFactory();
return new AutoValueGson_CommonTypeAdapterFactory();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static GsonBuilder builder() {
.registerTypeHierarchyAdapter(HashCode.class, new HashCodeJsonSerializer())
.registerTypeAdapter(PublicKey.class, new PublicKeyJsonSerializer())
.registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeJsonSerializer())
.registerTypeAdapterFactory(StoredConfigurationAdapterFactory.create())
.registerTypeAdapterFactory(CommonTypeAdapterFactory.create())
.setLongSerializationPolicy(LongSerializationPolicy.STRING);
}

Expand Down

This file was deleted.

This file was deleted.

9 changes: 8 additions & 1 deletion exonum-java-binding/core/findbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@
<Bug pattern="NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE"/>
</Match>

<!-- Exclude the auto-generated files.
Remove the rules below once https://github.com/spotbugs/spotbugs/issues/694 is resolved. -->

<!-- It is good, hashCode is specified in the parent, which is *the* way
to configure it in AutoValue -->
<Match>
<Class name="~.*AutoValue_Block"/>
<Bug pattern="HE_EQUALS_NO_HASHCODE"/>
</Match>

<!-- Exclude the auto-generated files -->
<Match>
<Class name="~.*AutoValue_Block.GsonTypeAdapter"/>
<Bug pattern="RV_RETURN_VALUE_IGNORED"/>
</Match>

<Match>
<Source name="~.*CoreProtos\.java"/>
</Match>
Expand Down
3 changes: 1 addition & 2 deletions exonum-java-binding/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@

<dependency>
<groupId>com.ryanharter.auto.value</groupId>
<artifactId>auto-value-gson-annotations</artifactId>
<!-- TODO: verify <scope>provided</scope>-->
<artifactId>auto-value-gson-runtime</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.base.Preconditions.checkState;

import com.exonum.binding.common.hash.HashCode;
import com.exonum.binding.core.blockchain.serialization.CoreTypeAdapterFactory;
import com.exonum.binding.core.service.Schema;
import com.google.auto.value.AutoValue;
import com.google.gson.Gson;
Expand Down Expand Up @@ -100,7 +101,7 @@ public int hashCode() {
/**
* Provides a Gson type adapter for this class.
*
* @see com.exonum.binding.core.blockchain.serialization.BlockAdapterFactory
* @see CoreTypeAdapterFactory
*/
public static TypeAdapter<Block> typeAdapter(Gson gson) {
return new AutoValue_Block.GsonTypeAdapter(gson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@
import com.ryanharter.auto.value.gson.GsonTypeAdapterFactory;

/**
* Class used to automatically create Gson type adapters for AutoValue classes.
* Note that you need to provide static factory method in your AutoValue class.
* Class used to automatically create Gson type adapters for all AutoValue classes
* located in this module.
*
* <p>Note that you need to provide an accessible static factory method in your AutoValue class.
*
* <pre><code>
* public static TypeAdapter&lt;Block&gt; typeAdapter(Gson gson) {
* return new AutoValue_Block.GsonTypeAdapter(gson);
* public static TypeAdapter&lt;TransactionResult&gt; typeAdapter(Gson gson) {
* return new AutoValue_TransactionResult.GsonTypeAdapter(gson);
* }
* </code></pre>
*
* @see <a href="https://github.com/rharter/auto-value-gson/#factory">
* Using TypeAdapterFactory</a>
*/
@GsonTypeAdapterFactory
public abstract class BlockAdapterFactory implements TypeAdapterFactory {
public abstract class CoreTypeAdapterFactory implements TypeAdapterFactory {

public static TypeAdapterFactory create() {
return new AutoValueGson_BlockAdapterFactory();
return new AutoValueGson_CoreTypeAdapterFactory();
}
}
4 changes: 2 additions & 2 deletions exonum-java-binding/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<equalsverifier.version>3.1.9</equalsverifier.version>
<javax-annotation-api.version>1.3.2</javax-annotation-api.version>
<gson.version>2.8.5</gson.version>
<auto-value-gson.version>0.8.0</auto-value-gson.version>
<auto-value-gson.version>1.0.0</auto-value-gson.version>
<!-- Default values of properties set by Jacoco when coverage is enabled.
Passed to the JVM running tests. -->
<jacoco.args></jacoco.args>
Expand Down Expand Up @@ -173,7 +173,7 @@

<dependency>
<groupId>com.ryanharter.auto.value</groupId>
<artifactId>auto-value-gson-annotations</artifactId>
<artifactId>auto-value-gson-runtime</artifactId>
<version>${auto-value-gson.version}</version>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
import com.exonum.binding.common.crypto.PublicKey;
import com.exonum.binding.common.hash.HashCode;
import com.exonum.binding.common.serialization.json.JsonSerializer;
import com.exonum.binding.common.serialization.json.TransactionLocationAdapterFactory;
import com.exonum.binding.common.serialization.json.TransactionResultAdapterFactory;
import com.exonum.binding.core.blockchain.serialization.BlockAdapterFactory;
import com.exonum.binding.core.blockchain.serialization.CoreTypeAdapterFactory;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
Expand Down Expand Up @@ -94,9 +92,7 @@ class ApiControllerIntegrationTest {
private static final HashCode HASH_1 = HashCode.fromInt(0x00);

private static final Gson JSON_SERIALIZER = JsonSerializer.builder()
.registerTypeAdapterFactory(BlockAdapterFactory.create())
.registerTypeAdapterFactory(TransactionLocationAdapterFactory.create())
.registerTypeAdapterFactory(TransactionResultAdapterFactory.create())
.registerTypeAdapterFactory(CoreTypeAdapterFactory.create())
.create();

@Mock
Expand Down