-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add serializer and deserializer for
Signature
(#305)
* add serializer and deserializer for `Signature` * WrappedSignature example interface and test * fix checkstyle * add `as = ImmutableSignature.class` back Co-authored-by: David Fuelling <[email protected]>
- Loading branch information
1 parent
e9aa7c4
commit 3a48818
Showing
5 changed files
with
80 additions
and
4 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
22 changes: 22 additions & 0 deletions
22
...-crypto-core/src/main/java/org/xrpl/xrpl4j/crypto/core/signing/SignatureDeserializer.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,22 @@ | ||
package org.xrpl.xrpl4j.crypto.core.signing; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import org.xrpl.xrpl4j.codec.addresses.UnsignedByteArray; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Deserializes signature string value to an object of type {@link Signature}. | ||
*/ | ||
class SignatureDeserializer extends JsonDeserializer<Signature> { | ||
|
||
@Override | ||
public Signature deserialize(JsonParser jsonParser, DeserializationContext ctxt) | ||
throws IOException { | ||
JsonNode node = jsonParser.getCodec().readTree(jsonParser); | ||
return Signature.builder().value(UnsignedByteArray.fromHex(node.asText())).build(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...4j-crypto-core/src/main/java/org/xrpl/xrpl4j/crypto/core/signing/SignatureSerializer.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,17 @@ | ||
package org.xrpl.xrpl4j.crypto.core.signing; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Custom Jackson serializer for {@link Signature}es. | ||
*/ | ||
class SignatureSerializer extends JsonSerializer<Signature> { | ||
@Override | ||
public void serialize(Signature signature, JsonGenerator gen, SerializerProvider provider) throws IOException { | ||
gen.writeString(signature.base16Value()); | ||
} | ||
} |
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