Trying to iterate and print detailsResp data in loggers

I used streams code to print xml object schema file data to iterate and print in object data value in logger but every time it's printing hash code format value only. highly appreciate your response on my query

sample response data : GetObjectDetailsResponse detailsResp :

<ns2:GetObjectDetailsResponse xmlns="http://../../schema">
  <header>
    ...
  </header>
  <ns2:addressDetails>
    ...
  </ns2:addressDetails>
  <ns2:accountNumberList>
   <accountNumber>123456789</accountNumber>
   <accountType>Saving</accountType>
  </ns2:accountNumberList>
</ns2:GetObjectDetailsResponse>
public class ExampleData {

  public ObjectDetails processData(GetObjectDetailsResponse detailsResp){
    value = processDetails(elementTag, index, detailsResp.getAccountNumberList());
    detailsResp.getAccountNumberList().stream().forEach(item -> logDebug("print getAccountNumberList value--->" + item);
  }
}
1

There are 1 best solutions below

1
Laurent Schoelens On

You can rely on 3rd party libraries for logging purpose (like the ToStringBuilder from apache commons-lang3)

You can then have readable from with one line of code

logDebug("print getAccountNumberList value--->" +
    ToStringBuilder.reflectionToString(item));

You can also add XJC-plugin during XSD -> JAVA code generation like the -XtoString XJC-plugin of jaxb-tools