Format source code
This commit is contained in:
parent
07ec8ad2dd
commit
28656559d2
|
@ -2568,32 +2568,29 @@ public abstract class ToStringStyle implements Serializable {
|
|||
protected void appendDetail(StringBuffer buffer, String fieldName, Object value) {
|
||||
|
||||
if (value == null) {
|
||||
|
||||
appendNullText(buffer, fieldName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (value instanceof String || value instanceof Character) {
|
||||
|
||||
appendValueAsString(buffer, value.toString());
|
||||
appendValueAsString(buffer, value.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (value instanceof Number || value instanceof Boolean) {
|
||||
|
||||
buffer.append(value);
|
||||
return;
|
||||
buffer.append(value);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
final String valueAsString = value.toString();
|
||||
if (valueAsString.startsWith(getContentStart()) && valueAsString.endsWith(getContentEnd())
|
||||
|| valueAsString.startsWith(getArrayStart()) && valueAsString.startsWith(getArrayEnd())
|
||||
) {
|
||||
|
||||
buffer.append(value);
|
||||
return;
|
||||
if (valueAsString.startsWith(getContentStart())
|
||||
&& valueAsString.endsWith(getContentEnd())
|
||||
|| valueAsString.startsWith(getArrayStart())
|
||||
&& valueAsString.startsWith(getArrayEnd())) {
|
||||
buffer.append(value);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
appendDetail(buffer, fieldName, valueAsString);
|
||||
}
|
||||
|
||||
|
|
|
@ -91,34 +91,32 @@ public class JsonToStringStyleTest {
|
|||
assertEquals("{\"a\":\"hello\",\"b\":\"world\"}", new ToStringBuilder(base)
|
||||
.appendSuper("{\"a\":\"hello\"}").append("b", "world").toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testChar() {
|
||||
|
||||
try {
|
||||
new ToStringBuilder(base).append('A').toString();
|
||||
fail("Should have generated UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
}
|
||||
|
||||
|
||||
assertEquals("{\"a\":\"A\"}", new ToStringBuilder(base).append("a", 'A')
|
||||
.toString());
|
||||
assertEquals("{\"a\":\"A\",\"b\":\"B\"}", new ToStringBuilder(base).append("a", 'A').append("b", 'B')
|
||||
.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDate() {
|
||||
|
||||
final Date now = new Date();
|
||||
final Date afterNow = new Date(System.currentTimeMillis() + 1);
|
||||
|
||||
|
||||
try {
|
||||
new ToStringBuilder(base).append(now).toString();
|
||||
fail("Should have generated UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
}
|
||||
|
||||
|
||||
assertEquals("{\"now\":\"" + now.toString() +"\"}", new ToStringBuilder(base).append("now", now)
|
||||
.toString());
|
||||
assertEquals("{\"now\":\"" + now.toString() +"\",\"after\":\"" + afterNow.toString() + "\"}", new ToStringBuilder(base).append("now", now).append("after", afterNow)
|
||||
|
|
Loading…
Reference in New Issue