Skip to content

Commit

Permalink
one more json
Browse files Browse the repository at this point in the history
  • Loading branch information
rainer-prosi committed Mar 3, 2023
1 parent 3f68503 commit 75bee44
Showing 1 changed file with 54 additions and 51 deletions.
105 changes: 54 additions & 51 deletions src/main/java/org/cip4/lib/jdf/jsonutil/JSONWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -771,66 +771,69 @@ else if (eJSONCase.upper.equals(jCase))

Object getObjectFromVal(final String key, final String val)
{
if (typeSafe && isTypesafeKey(key))
if (typeSafe)
{
final String normalized = StringUtil.normalize(key, true, "_ -");
final String normalized2 = StringUtil.token(normalized, 1, "/");

if (isArrayKey(key) || isArrayKey(normalized2))
if (isTypesafeKey(normalized) && isTypesafeKey(normalized2))
{
final StringArray a = StringArray.getVString(val, null);
if (a != null)

if (isArrayKey(key) || isArrayKey(normalized2))
{
final JSONArray ar = new JSONArray();
for (final String s : a)
final StringArray a = StringArray.getVString(val, null);
if (a != null)
{
final String k2 = getKey(s, valueCase);
if (k2 != null)
final JSONArray ar = new JSONArray();
for (final String s : a)
{
ar.add(k2);
final String k2 = getKey(s, valueCase);
if (k2 != null)
{
ar.add(k2);
}
}
return ar;
}
return ar;
}
}
else if ((numList.contains(normalized) || numList.contains(normalized2)) && JDFNumberList.createNumberList(val) != null)
{
return getNumListArray(val);
}
else if ((numbers.contains(normalized) || numbers.contains(normalized2)) && StringUtil.isNumber(val))
{
return getNumber(val);
}
else if ((bool.contains(normalized) || bool.contains(normalized2)) && StringUtil.isBoolean(val))
{
return Boolean.valueOf(StringUtil.parseBoolean(val, true));
}
else if (isTransferCurve(key) || isTransferCurve(normalized2))
{
return getTransferCurve(val);
}
else if (StringUtil.isNumber(val))
{
numbers.add(normalized);
return getNumber(val);
}
else if (StringUtil.isBoolean(val))
{
bool.add(normalized);
return Boolean.valueOf(val);
}
else if (JDFNumberList.createNumberList(val) != null)
{
numbers.remove(normalized);
numList.add(normalized);
return getNumListArray(val);
}
if (addString(key))
{
numbers.remove(normalized);
bool.remove(normalized);
numList.remove(normalized);
log.info("found new string type: " + key);
else if ((numList.contains(normalized) || numList.contains(normalized2)) && JDFNumberList.createNumberList(val) != null)
{
return getNumListArray(val);
}
else if ((numbers.contains(normalized) || numbers.contains(normalized2)) && StringUtil.isNumber(val))
{
return getNumber(val);
}
else if ((bool.contains(normalized) || bool.contains(normalized2)) && StringUtil.isBoolean(val))
{
return Boolean.valueOf(StringUtil.parseBoolean(val, true));
}
else if (isTransferCurve(key) || isTransferCurve(normalized2))
{
return getTransferCurve(val);
}
else if (StringUtil.isNumber(val))
{
numbers.add(normalized);
return getNumber(val);
}
else if (StringUtil.isBoolean(val))
{
bool.add(normalized);
return Boolean.valueOf(val);
}
else if (JDFNumberList.createNumberList(val) != null)
{
numbers.remove(normalized);
numList.add(normalized);
return getNumListArray(val);
}
if (addString(key))
{
numbers.remove(normalized);
bool.remove(normalized);
numList.remove(normalized);
log.info("found new string type: " + key);
}
}
}
return updateCase(StringUtil.getNonEmpty(val), valueCase);
Expand Down Expand Up @@ -899,7 +902,7 @@ boolean isTransferCurve(final String key)
public boolean isTypesafeKey(final String key)
{
final String normalized = StringUtil.normalize(key, true, "_ -");
return normalized != null && !alwaysString.contains(normalized);
return normalized == null || !alwaysString.contains(normalized);
}

boolean isArrayKey(final String key)
Expand Down

0 comments on commit 75bee44

Please sign in to comment.