Closed agwego closed 6 years ago
Yes. I've been thinking about this as well. The simplest solution I was thinking is just to set a "String" type Asset. This way, it can be any json string format value. The developers would need to then create a model of their own and just deserialize it with GSON as well.
so in the builder:
ITransactionAttributes addAssets(String freeFormJsonData);
Introduce a new Asset Type object that accepts String only
@SerializedName("data")
private String data;
This is the simplest way to approach it I think.
Alvin I'd like to take this on, I think it be best if we could allow arbitrary objects to be used and not force users of the api to convert to String before setting. For complex objects that GSON isn't capable of we could provide and interface that adds serializers/deserializers the implementer would use or allow them to register type adapters. This also apply's to meta-data.
@agwego sure. just submit the PR and we'll review. Thank you.
Some new information has come to light, and although Asset.data and metadata can be JsonObject it would appear that the transaction spec will be changing in the future to only allow leaf node types of: String, Boolean, null. array [], object {}.
Which means, all other types like BigDecimal, Integer will have to be stringified. Sigh, JSON was a poor choice for a data transport.
See: https://github.com/bigchaindb/js-bigchaindb-driver/issues/88 https://github.com/bigchaindb/bigchaindb/issues/1900 https://github.com/bigchaindb/bigchaindb/issues/1932
I actually have the generic code working for meta-data, i.e. any suitable JSONObject. Which I'll leave as is since it actually adheres to the specification as currently written.
This is a pretty big change.
Reading the BigchainDB specs data for an asset can be any valid JSON object. To that end BlockApiTest and AssetsApiTest are failing because of data elements like the following: ''' "data": { "CV": { "FirstName": "John", "LastName": "Doe" } }, "id": "dd67b1fb2ca4ef6649e174b602e5d92a3844b07d3f4027683a60a6efe73cbfe5" ''' See "Asset" from the BigchainDB docs: https://docs.bigchaindb.com/projects/server/en/latest/schema/transaction.html#asset
I may try and tackle this.