René Schöne (b9ad898b) at 25 Jul 17:02
replace isBlank with java8 compatible method
René Schöne (b78beaf5) at 25 Jul 16:06
René Schöne (b78beaf5) at 25 Jul 16:04
When using the method ComplexElement.makeStringElement(String value)
, more special characters need to be checked for.
Currently only [
,{
,\
,"
,\n
are searched for, but the full list includes :
,,
,#
,[
,{
,"
,\n
Furthermore, it should be checked for null
and blank values.
Suggested fix in Helpers.jrag:
// --- helper methods for put/add ---
protected SimpleElement ComplexElement.makeStringElement(String value) {
+ if (value == null || value.equals("null")) {
+ return StringElement.of("null");
+ }
+ if (value.isBlank()) {
+ return StringElement.of(value);
+ }
// simple test, check for special characters
- return containsAny(value, "[{\"\n") ?
+ return containsAny(value, ":#,[{\"\n") ?
StringElement.of(value.replace("\n", "\\n").replace("\"", "\\\"")) :
ValueElement.of(value);
}
A NullPointerException
is thrown when:
new KeyValuePair().setKey("key").setValue(null).prettyPrint();
Suggested fix in Printing.jrag
:
protected StringBuilder KeyValuePair.prettyPrint(StringBuilder sb, boolean printIndent, String indent) {
if (printIndent) sb.append(indent);
if (isCollapsed()) {
sb.append("\"");
}
sb.append(getKey());
if (isCollapsed()) {
sb.append("\"");
}
sb.append(":");
- if (getValue().isComplexElement() && !getValue().isEmpty() && !getValue().isCollapsed()) {
+ if (getValue() == null) {
+ sb.append(" null");
+ } else if (getValue().isComplexElement() && !getValue().isEmpty() && !getValue().isCollapsed()) {
sb.append("\n");
getValue().prettyPrint(sb, true, indent + PRINT_INDENT);
} else {
sb.append(" ");
getValue().prettyPrint(sb, false, indent);
}
return sb;
}
When using the method ComplexElement.makeStringElement(String value)
, more special characters need to be checked for.
Currently only [
,{
,\
,"
,\n
are searched for, but the full list includes :
,,
,#
,[
,{
,"
,\n
Furthermore, it should be checked for null
and blank values.
Suggested fix in Helpers.jrag:
// --- helper methods for put/add ---
protected SimpleElement ComplexElement.makeStringElement(String value) {
+ if (value == null || value.equals("null")) {
+ return StringElement.of("null");
+ }
+ if (value.isBlank()) {
+ return StringElement.of(value);
+ }
// simple test, check for special characters
- return containsAny(value, "[{\"\n") ?
+ return containsAny(value, ":#,[{\"\n") ?
StringElement.of(value.replace("\n", "\\n").replace("\"", "\\\"")) :
ValueElement.of(value);
}
A NullPointerException
is thrown when:
new KeyValuePair().setKey("key").setValue(null).prettyPrint();
Suggested fix in Printing.jrag
:
protected StringBuilder KeyValuePair.prettyPrint(StringBuilder sb, boolean printIndent, String indent) {
if (printIndent) sb.append(indent);
if (isCollapsed()) {
sb.append("\"");
}
sb.append(getKey());
if (isCollapsed()) {
sb.append("\"");
}
sb.append(":");
- if (getValue().isComplexElement() && !getValue().isEmpty() && !getValue().isCollapsed()) {
+ if (getValue() == null) {
+ sb.append(" null");
+ } else if (getValue().isComplexElement() && !getValue().isEmpty() && !getValue().isCollapsed()) {
sb.append("\n");
getValue().prettyPrint(sb, true, indent + PRINT_INDENT);
} else {
sb.append(" ");
getValue().prettyPrint(sb, false, indent);
}
return sb;
}