mpark
June 29, 2021, 10:06pm
1
After studying the codes in ColdFusion, I believe that any properties in an entity that is marked with remotingfetch=“false” are skipped when serializeJson function is called.
On Lucee, I expected a similar behavior, but Lucee still serializes properties with remotingfetch=“false”.
I looked through the implementation of SerializeJson and I think Lucee ignores the remotingfetch in its implementation of serializejson.
Instantiation of JSONConverter in SerializeJson.java. ignoreRemotingFetch is hard-coded to ‘true’
}
// charset
else if (!StringUtil.isEmpty(useSecureJSONPrefixOrCharset)) {
cs = CharsetUtil.toCharset(Caster.toString(useSecureJSONPrefixOrCharset));
}
return _call(pc, var, queryFormat, cs, useSecureJSONPrefix);
}
private static String _call(PageContext pc, Object var, Object queryFormat, Charset charset, boolean useSecureJSONPrefix) throws PageException {
try {
JSONConverter json = new JSONConverter(true, charset, JSONDateFormat.PATTERN_CF);
int qf = JSONConverter.toQueryFormat(queryFormat, SerializationSettings.SERIALIZE_AS_UNDEFINED);
if (qf == SerializationSettings.SERIALIZE_AS_UNDEFINED) {
if (!StringUtil.isEmpty(queryFormat)) throw new FunctionException(pc, SerializeJSON.class.getSimpleName(), 2, "queryFormat",
"When var is a Query, argument [queryFormat] must be either a boolean value or a string with the value of [struct], [row], or [column]");
ApplicationContextSupport acs = (ApplicationContextSupport) pc.getApplicationContext();
SerializationSettings settings = acs.getSerializationSettings();
qf = settings.getSerializeQueryAs();
}
Constructor in JSONConverter.java
private Key commentName;
/**
* @param ignoreRemotingFetch
* @param charset if set, characters not supported by the charset are escaped.
* @param patternCf
*/
public JSONConverter(boolean ignoreRemotingFetch, Charset charset) {
this(ignoreRemotingFetch, charset, JSONDateFormat.PATTERN_CF, null, false, null);
}
public JSONConverter(boolean ignoreRemotingFetch, Charset charset, String pattern) {
this(ignoreRemotingFetch, charset, pattern, null, false, null);
}
public JSONConverter(boolean ignoreRemotingFetch, Charset charset, String pattern, Boolean preserveCase) {
this(ignoreRemotingFetch, charset, pattern, preserveCase, false, null);
}
public JSONConverter(boolean ignoreRemotingFetch, Charset charset, String pattern, Boolean preserveCase, boolean multiline) {
this(ignoreRemotingFetch, charset, pattern, preserveCase, multiline, null);
Checking of ignoreRemotingFetch member variable
sb.append(':');
_serialize(pc, test, value, sb, queryFormat, done);
}
if (struct instanceof Component) {
Boolean remotingFetch;
Component comp = (Component) struct;
boolean isPeristent = false;
isPeristent = comp.isPersistent();
Property[] props = comp.getProperties(false, true, false, false);
ComponentScope scope = comp.getComponentScope();
for (int i = 0; i < props.length; i++) {
if (!ignoreRemotingFetch) {
remotingFetch = Caster.toBoolean(props[i].getDynamicAttributes().get(REMOTING_FETCH, null), null);
if (remotingFetch == null) {
if (isPeristent && ORMUtil.isRelated(props[i])) continue;
}
else if (!remotingFetch.booleanValue()) continue;
}
Is there any reason why Lucee might ignore this particular property?