You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
one of our customers is using PHP to connect to our backend. Every
time he sends empty values for a map with PHP, the JSON content is
parsed as array (since in PHP, there are only associative arrays
whereas emtpy ones look identical to usual arrays).
If one could modify the MapDeserializer class, method "deserialize"
to the following:
[...]
if ( t != JsonToken.START_OBJECT && t !=
JsonToken.FIELD_NAME && t != JsonToken.END_OBJECT )
{
// [JACKSON-620] (empty) String may be ok however:
if ( t == JsonToken.VALUE_STRING )
{
return ( Map<Object, Object> )
this._valueInstantiator.__createFromString( jp.getText( ) );
}
// empty PHP map looks like an array
if ( t == JsonToken.START_ARRAY )
{
return new HashMap<Object, Object>( );
}
throw ctxt.mappingException( getMapClass( ) );
}
[...]
This should solve the problem. Maybe it would be nice to make this
configurable as a feature in the mapper.
The text was updated successfully, but these errors were encountered:
Have you tried running that code? It does not match END_ARRAY; nor consider what happens to contents -- even though in this particular case you expect empty array, it has to consider case of elements within array.
I think something more is needed to also allow this behaviour, because it can easily mask actual error cases (content mismatch).
So I agree that something similar to above would help handle PHP oddity of empty array to represent empty Map (and/or Objects). But there is bit more design to do to make sure the new feature works with other aspects of data binding.
Hi,
The text was updated successfully, but these errors were encountered: