Skip to content

ToString should print all the values if no Annotation exist  #50

@rhkiswani

Description

@rhkiswani

private String normalToString(Object obj) {
StringBuilder builder = new StringBuilder();
List fields = getFieldsByAnnotation(obj, ToString.class, false);
if (ArraysUtils.isEmpty(fields)){
fields = getFieldsByAnnotation(obj, EqualsField.class, false);
}
if (ArraysUtils.isEmpty(fields)){
fields = getFieldsByAnnotation(obj, HashcodeField.class, true);
}
for (int i = 0; i < fields.size() ; i++) {
Field f = fields.get(i);
Object fieldValue = reflectionHelper.getFieldValue(obj, f.getName());
if (fieldValue == null){
continue;
}
builder.append(f.getName());
builder.append("=");
if ((fieldValue.getClass().isArray() || Collection.class.isInstance(fieldValue))){
builder.append(gosnToString(fieldValue));
} else {
builder.append(FormatUtil.format("{0}", fieldValue));
}
if ( i < fields.size() -1){
builder.append(", ");
}
}
return builder.toString();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions