tracker issue : CF-4206423

select a category, or use search below
(searches all categories and all time range)
Title:

New Metadata Mutation Makes Booleans Incompatibile with Gson library

| View in Tracker

Status/Resolution/Reason: To Fix//BugVerified

Reporter/Name(from Bugbase): Jon C. / ()

Created: 12/18/2019

Components: Core Runtime

Versions: 2018

Failure Type: Data Corruption

Found In Build/Fixed In Build: 2018.0.03.314033 /

Priority/Frequency: Normal / Some users will encounter

Locale/System: English / Linux

Vote Count: 3

Problem Description:
In ACF2018, booleans declared in structs have a metadata mutation that causes the Gson library ( https://www.javadoc.io/doc/com.google.code.gson/gson/latest/com.google.gson/com/google/gson/Gson.html ) to serialize a boolean to JSON as a nested object: {"value":true,"image":"true"}.  This Gson library is frequently used in CF integrations with java libraries.

This problem does not exist in previous versions of Adobe Coldfusion.

Steps to Reproduce:

1. Add the Gson JAR to the class path or application library
2. Put the following code in onRequestStart of Application.cfc:

var document = {
	"foo" : "bar",
	"bar" : {
		"foo" : true
	}
};

var jLoader = wirebox.getInstance( "loader@cbjavaloader" );
writeDump( createObject( "java", "com.google.gson.Gson" ).init().toJson( document ) );

document.bar["baz"] = {
	"foo" : false
};

writeDump( createObject( "java", "com.google.gson.Gson" ).init().toJson( document ) );

abort;

Actual Result:

{"bar":{"foo":{"value":true,"image":"true"}},"foo":"bar"} 
{"bar":{"foo":{"value":true,"image":"true"},"baz":{"foo":{"value":false,"image":"false"}}},"foo":"bar"}

All declared booleans are serialized as nested objects

Expected Result:

{"bar":{"foo":true },"foo":"bar"} {"bar":{"foo":true,"baz":{"foo":true}},"foo":"bar"}

All booleans should be serialized as booleans

Any Workarounds:

Explicit javacasting of every declared or running the object through deserializeJSON( serializeJSON( document ) ).

Attachments:

Comments: