[
https://issues.apache.org/jira/browse/IGNITE-9043?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16568207#comment-16568207
]
Vladimir Ozerov commented on IGNITE-9043:
-----------------------------------------
[~dmekhanikov], looks good to me.
> Collections cannot be assigned to fields of type Object in BinaryObject
> -----------------------------------------------------------------------
>
> Key: IGNITE-9043
> URL: https://issues.apache.org/jira/browse/IGNITE-9043
> Project: Ignite
> Issue Type: Bug
> Components: binary
> Affects Versions: 2.6
> Reporter: Denis Mekhanikov
> Assignee: Denis Mekhanikov
> Priority: Major
> Labels: usability
> Fix For: 2.7
>
>
> When a binary type is registered during first insertion without use of
> BinaryObject, then fields of type {{Map}} are registered as {{Object}}-s.
> But if you try to assign a {{HashMap}} to this field afterwards, then
> exception is thrown.
> The following code results in an exception:
> {code:java}
> public static void main(String[] args) {
> Ignite ignite = Ignition.start("config/ignite.xml");
> IgniteCache<Integer, ExamplePojo> cache =
> ignite.getOrCreateCache("cache");
> cache.put(1, new ExamplePojo());
> BinaryObject val = cache.<Integer, BinaryObject>withKeepBinary().get(1);
> Map<Integer, String> map = val.field("map");
> BinaryObjectBuilder bldr = val.toBuilder();
> bldr.setField("map", map);
> bldr.build(); // Throws exception.
> }
> static class ExamplePojo {
> Map<Integer, String> map = new HashMap<>();
> }
> {code}
> Stacktrace:
> {noformat}
> Exception in thread "main" class
> org.apache.ignite.binary.BinaryObjectException: Wrong value has been set
> [typeName=binary.BinaryObjectMapExample$ExamplePojo, fieldName=map,
> fieldType=Object, assignedValueType=Map]
> at
> org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl.checkMetadata(BinaryObjectBuilderImpl.java:428)
> at
> org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl.serializeTo(BinaryObjectBuilderImpl.java:223)
> at
> org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl.build(BinaryObjectBuilderImpl.java:183)
> at binary.BinaryObjectMapExample.main(BinaryObjectMapExample.java:26)
> {noformat}
> It would be convenient, if objects of any type could be written as {{Object}}
> without the need to specify the type explicitly in
> {{BinaryObjectBuilder.setField(...)}} method.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)