1

This is my code for transaction history:

@RequestMapping(value = EmpRestURIConstants.TRANS_HIS, method = RequestMethod.POST)
    public @ResponseBody TransactionsRequestBuilder transactionHistory(@RequestBody stellarModel stellm) {
        logger.info("Start transactionHistory.");
        KeyPair source = KeyPair.fromSecretSeed(stellm.getSeed());
        TransactionsRequestBuilder tr = server.transactions().forAccount(source);
        return tr;
    }

It gives the following error:

2019-04-15 11:47:01.839  WARN 18689 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class org.stellar.sdk.requests.TransactionsRequestBuilder]

I am stuck with this for two days, any help would be greatly appreciated.

I tried this as suggested:

@RequestMapping(value = StellRestURIConstants.TRANS_HIS, method = RequestMethod.POST)
    public @ResponseBody ArrayList<TransactionResponse> transactionHistory(@RequestBody stellarModel stellm) {
        logger.info("Start transactionHistory.");
        ArrayList<TransactionResponse> arr = new ArrayList<TransactionResponse>();
        KeyPair source = KeyPair.fromSecretSeed(stellm.getSeed());

        TransactionsRequestBuilder tr = server.transactions().forAccount(source);
        try {
            arr = tr.execute().getRecords() ;
        } catch (TooManyRequestsException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println("aaaaaaaa");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println("bbbbbbb");

        }
        return arr;

    }

It gives the below error:

"timestamp": "2019-04-15T10:34:50.439+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Could not write JSON: (was java.lang.NullPointerException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: java.util.ArrayList[0]->org.stellar.sdk.responses.TransactionResponse[\"sourceAccount\"]->org.stellar.sdk.KeyPair[\"secretSeed\"])",
    "path": "/transaction_history"
5
  • Absolutely no knowledge about java-sdk but i think forAccount might expect the public accountId as param, not the whole keypair. Its probably sth. like source.publicKey()
    – sui
    Commented Apr 15, 2019 at 7:25
  • fromSecretSeed(stellm.getSeed()) will return account id Commented Apr 15, 2019 at 7:26
  • even in transaction it contain method to get account id :public TransactionsRequestBuilder forAccount(KeyPair account) { account = checkNotNull(account, "account cannot be null"); this.setSegments("accounts", account.getAccountId(), "transactions"); return this; } Commented Apr 15, 2019 at 7:27
  • Isn't Keypair a keypair object that represents both, secret seed and public id? I'd assume you have to pass the public String "G...." only.
    – sui
    Commented Apr 15, 2019 at 7:33
  • Ok, seems different to the javascript sdk that I was working with.
    – sui
    Commented Apr 15, 2019 at 7:35

1 Answer 1

0

This is not related to Stellar. The error tells us that SpringFramework does not know how to convert TransactionsRequestBuilder to an HTTP response.

I suspect you don't want to return the builder, but the result of calling .execute().getRecords() on the builder.

later...

You tried this and got a new error message. Here's what I think is going on.

The @ResponseBody annotation tells spring to automatically convert your response object to JSON in the body of the response. For that to work, the return items needs to have accessible, non-null fields.

The Java SDK KeyPair object is used in the TransactionResponse, despite the response not containing the secret seed. The library sets the value as null. Spring doesn't know how to render this.

I'm not familiar with modern Spring, but I'm fairly certain this is what's happening. The long-term solution might be to modify the SDK so that the field is tagged as optional in a way Spring recognises. I don't know. That would take some investigation.

The immediate alternative for you is to not use @ResponseBody, but to use the ResponseEntity return type instead. This gives you the ability to map the TransactionResponse into a response directly. See the Spring tutorial (search for ResponseEntity in that page).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.