Open sublimator opened 10 years ago
This needs prioritizing, b4 people start to use the lib
Can use Jackson, along with it's support for the builder pattern, stream -> object mapping, to create Transaction/LedgerEntry subclasses with plain old fields, rather using Field enum as keys into a TreeMap. Make as many SerializedType implementors immutable.
// on the Amount class ....
@JsonDeserialize(builder = Amount.Builder.class)
public class Amount extends Number implements SerializedType, Comparable<Amount>
{
...
@JsonPOJOBuilder()
public static class Builder {
public AccountID issuer;
public BigDecimal value;
public Currency currency;
public Builder(String value) {
Amount amount = fromString(value);
issuer = amount.issuer;
this.value = amount.value;
currency = amount.currency;
}
public Builder() {}
public Amount build() {
return new Amount(value, currency, issuer, currency.isNative());
}
}
// In client code
Amount amount = mapper.readValue(
"{\"value\" : \"11234.0005\", " +
"\"issuer\" : \"rKyGunStozzRBNnnrMXqCZ3wVbgXgCGxji\", " +
"\"currency\" : \"USD\"}", Amount.class);
Will need to investigate the use of jackson reflection infrastructure for serializing objects to bytes also. Can then just create clases like this:
public class OfferCreate extends Transaction {
public UInt32 Expiration;
public Amount TakerPays;
...
}
This is my first GitHub comment ever and currently starting to learn the Git stuff, so sorry if I do noob stuff. Yes, I agree Jackson or Gson are the only 2 good options. I have forked this project and will see if I can start implementing Jackson.
http://examples.javacodegeeks.com/core-java/json/jackson/convert-java-object-to-from-json-using-jackson-example/