2017-12-12 21 views
1

나는 구현 toString 방법이 있습니다어떻게 ReflectionToStringBuilder를 사용하고 날짜를 읽을 수있는 문자열로 지정할 수 있습니까? 아래 작성된

이 잘 작동하지만 타임 스탬프 (그리고, 나는, 날짜 가정)을 보여줄 것이다 개체에 일반 toString로 표시됩니다
public String toString() { 
    return new ReflectionToStringBuilder(this, new MultilineRecursiveToStringStyle()).toString(); 
} 

:

[email protected][ 
    nanos=0 
], 

ReflectionToStringBuilder Date 개체의 서식을 어떻게 지정합니까?

+0

Javadoc을 읽었습니까? 액세스 가능한 모든 필드의 형식을 제어하는 ​​데 사용할 수있는 콜백이 있습니다. –

답변

0

예. ReflectionToStringBuilder은 다음을 허용합니다 :

new ReflectionToStringBuilder(this) { 
    @Override 
    protected Object getValue(Field field) throws IllegalArgumentException, IllegalAccessException { 
    if (Timestamp.class.equals(field.getType())) { 
     return "convert timestamp to String"; 
    } else { 
     return super.getValue(field); 
    } 
    } 
}