Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created public Json Serializer [ECR-2708]
- Loading branch information
1 parent
5c5104d
commit b6c060b
Showing
23 changed files
with
101 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ing-common/src/main/java/com/exonum/binding/common/serialization/json/JsonSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2018 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.common.serialization.json; | ||
|
||
import com.exonum.binding.common.crypto.PublicKey; | ||
import com.exonum.binding.common.hash.HashCode; | ||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.LongSerializationPolicy; | ||
|
||
/** | ||
* Provides configured {@link Gson} serializer for converting java objects to Json and vice versa. | ||
*/ | ||
public final class JsonSerializer { | ||
|
||
/** | ||
* Returns preconfigured {@link Gson} builder instance. Can be useful in cases when | ||
* some customization is required. For example, type adapters should be extended or replaced. | ||
*/ | ||
public static GsonBuilder builder() { | ||
return new GsonBuilder() | ||
.registerTypeHierarchyAdapter(HashCode.class, new HashCodeJsonSerializer()) | ||
.registerTypeAdapter(PublicKey.class, new PublicKeyJsonSerializer()) | ||
.registerTypeAdapterFactory(StoredConfigurationAdapterFactory.create()) | ||
.setLongSerializationPolicy(LongSerializationPolicy.STRING); | ||
} | ||
|
||
/** | ||
* Returns preconfigured {@link Gson} instance. | ||
*/ | ||
public static Gson json() { | ||
return builder().create(); | ||
} | ||
|
||
private JsonSerializer() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 0 additions & 72 deletions
72
.../java/com/exonum/binding/common/serialization/json/StoredConfigurationGsonSerializer.java
This file was deleted.
Oops, something went wrong.
80 changes: 0 additions & 80 deletions
80
...a/com/exonum/binding/common/serialization/json/StoredConfigurationGsonSerializerTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
...in/java/com/exonum/binding/cryptocurrency/transactions/CryptocurrencyTransactionGson.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.