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
8 changes: 7 additions & 1 deletion exonum-java-binding/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
format instead of the whole message in binary form.
- RocksDB library is no longer required to be installed on Mac or Linux to run
the Exonum Java application. (#902)

### Fixed
- The default [`Transaction#info`][tx-info-07] implementation causing an error on `transaction`
request. It is modified to return an empty object (no info) by default. (#904)

[tx-info-07]: https://exonum.com/doc/api/java-binding-core/0.7.0/com/exonum/binding/transaction/Transaction.html#info()

## [0.6.0]- 2019-05-08
## [0.6.0] - 2019-05-08

**If you are upgrading an existing Java service, consult
the [migration guide](https://github.com/exonum/exonum-java-binding/blob/ejb/v0.6.0/exonum-java-binding/doc/Migration_guide_0.6.md).**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
/**
* Provides {@link Gson} serializer for converting Java objects to Json and vice versa.
* It is configured to serialize Exonum objects in a format, compatible with the core framework
* and light clients (e.g., {@link HashCode} as a hex string).
* and light clients (e.g., {@link HashCode} as a hex string). If needed, a new serializer
* with adapters for service-specific types can be {@linkplain #builder() created}, with
* Exonum types support already included.
*/
public final class JsonSerializer {

Expand All @@ -50,8 +52,8 @@ public static GsonBuilder builder() {
}

/**
* Returns preconfigured {@link Gson} instance. Helpful in cases when no additional configuration
* of the Json serializer is required.
* Returns preconfigured {@link Gson} instance. Helpful in cases when no additional
* {@linkplain #builder() configuration} of the Json serializer is required.
*/
public static Gson json() {
return INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,24 @@ public interface Transaction {
void execute(TransactionContext context) throws TransactionExecutionException;

/**
* Returns some information about this transaction in JSON format.
* Returns the information about this transaction in JSON format.
* For example, it is included in the blockchain explorer response to
* a <a href="https://exonum.com/doc/version/0.11/advanced/node-management/#transaction">
* transaction</a> request.
*
* <p>By default, no information is provided. If needed, it can be easily implemented
* with {@linkplain com.exonum.binding.common.serialization.json.JsonSerializer Gson}:
*
* <pre><code>
* &#64;Override
* public String info() {
* return JsonSerializer.json().toJson(this);
* }
* </code></pre>
*/
default String info() {
return "";
// Empty object by default
return "{}";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2019 The Exonum Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.exonum.binding.transaction;

import static org.assertj.core.api.Assertions.assertThat;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.util.Map;
import org.junit.jupiter.api.Test;

class TransactionTest {

@Test
void infoIsEmptyByDefault() {
Transaction tx = context -> {
// no-op
};

String info = tx.info();

// Check it is correctly deserialized to an empty object
Gson gson = new Gson();
Map<String, ?> deserialized = gson.fromJson(info, new TypeToken<Map<String, ?>>() {
}.getType());
assertThat(deserialized).isEmpty();
}
}