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

Add string representation for all POJOs #12

Open
dexX7 opened this issue Oct 3, 2015 · 1 comment
Open

Add string representation for all POJOs #12

dexX7 opened this issue Oct 3, 2015 · 1 comment
Labels
good first issue A good issue for first-time contributors help wanted

Comments

@dexX7
Copy link
Member

dexX7 commented Oct 3, 2015

Let me quickly describe what issue I faced yesterday:

I wanted to dump some intermediate results, in particular of listUnspent, which returns a List of UnspentOutputs.

The change was basically:

@@ -166,2 +166,3 @@ class SendToOwnersReorgSpec extends BaseReorgSpec {
         when: "creating a third STO transaction"
+        println listUnspent(0, 999999)
         def thirdTxid = omniSendSTO(actorAddress, tokenID, 50.divisible)

However, the result:

[com.msgilligan.bitcoinj.json.pojo.UnspentOutput@3a13055a, ...]

It would be nice, if the UnspentOutput (and others) would be converted to something readable, such as:

[{"txid":"hex","vout":n,"address":"1base58",...}, ...]

The Groovy @ToString() class annotation may be useful?

@msgilligan
Copy link
Member

If the POJOs were POGOs we could use the Groovy @toString annotation, but I think we want to keep the core functionality in straight Java.

I've heard good things about Project Lombok that has similar features (including a @toString annotation) for straight Java, but at the expense of additional compile-time and IDE tooling. I'm leaning against using it for this project, but would like to try it out on another project sometime. (There's also a prototype implementation of using Groovy annotations to make POJOs, see GROOVY-7492.)

I think there are two approaches worth considering:

  1. Write toString() methods by hand.

  2. Use the Jackson ObjectMapper to convert to JSON String:

    println mapper.writeValueAsString(listUnspent(0, 999999))
    

We may be able to add some Groovy code to tests to make (2) more easily accessible or perhaps even automatic.

@msgilligan msgilligan added good first issue A good issue for first-time contributors help wanted labels Oct 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue A good issue for first-time contributors help wanted
Projects
None yet
Development

No branches or pull requests

2 participants