Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data for an asset can be any valid json object, not necessarily a Map<String,String> currently. #36

Closed
agwego opened this issue Nov 21, 2017 · 5 comments
Assignees

Comments

@agwego
Copy link
Contributor

agwego commented Nov 21, 2017

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.

@alvin-reyes
Copy link
Collaborator

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.

@agwego
Copy link
Contributor Author

agwego commented Nov 29, 2017

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.

see: https://docs.bigchaindb.com/projects/server/en/latest/appendices/tx-yaml-files.html#the-transaction-schema-files

@alvin-reyes
Copy link
Collaborator

@agwego sure. just submit the PR and we'll review. Thank you.

@alvin-reyes alvin-reyes assigned agwego and unassigned alvin-reyes Nov 30, 2017
@agwego
Copy link
Contributor Author

agwego commented Jan 4, 2018

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:
bigchaindb/js-bigchaindb-driver#88
bigchaindb/bigchaindb#1900
bigchaindb/bigchaindb#1932

@agwego
Copy link
Contributor Author

agwego commented Jan 4, 2018

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.

@agwego agwego closed this as completed Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants