From e8db7237a9c347d2225fce9b49ff92bb741adffa Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Fri, 1 May 2015 23:54:03 +0200 Subject: [PATCH] Extract logic for checking string representation of objects into separate methods --- .../commons/lang3/builder/ToStringStyle.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java b/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java index f988f0e9a..fbb40474d 100644 --- a/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java +++ b/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java @@ -2583,10 +2583,7 @@ public abstract class ToStringStyle implements Serializable { } final String valueAsString = value.toString(); - if (valueAsString.startsWith(getContentStart()) - && valueAsString.endsWith(getContentEnd()) - || valueAsString.startsWith(getArrayStart()) - && valueAsString.startsWith(getArrayEnd())) { + if (isJsonObject(valueAsString) || isJsonArray(valueAsString)) { buffer.append(value); return; } @@ -2594,6 +2591,16 @@ public abstract class ToStringStyle implements Serializable { appendDetail(buffer, fieldName, valueAsString); } + private boolean isJsonArray(String valueAsString) { + return valueAsString.startsWith(getArrayStart()) + && valueAsString.startsWith(getArrayEnd()); + } + + private boolean isJsonObject(String valueAsString) { + return valueAsString.startsWith(getContentStart()) + && valueAsString.endsWith(getContentEnd()); + } + /** * Appends the given String in parenthesis to the given StringBuffer. *