[ 
https://issues.apache.org/jira/browse/IGNITE-11013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16749863#comment-16749863
 ] 

Alexey Kosenchuk commented on IGNITE-11013:
-------------------------------------------

[~thavlik]

You did not set a type of the "nest" field in the "ty" object using 
setFieldType() method. That's why the client uses a default type for it - 
BinaryObject.

The correct first two lines in your example should be:

{{const nest = new ComplexObjectType(\{ num: 0 });}}
{{const ty = new ComplexObjectType(\{ foo: "", nest : null 
}).setFieldType("nest", nest);}}

Please try it.

And please read the comments for the ComplexObjectType constructor.

{{jsObject}} is not a type specification but a template of JavaScript Object 
which will be mapped to/from this complex type.

"The JavaScript Object defines a set of fields of the complex type.
By default, the fields have no types specified. It means during operations the 
Ignite client
will try to make automatic mapping between JavaScript types and Ignite object 
types -
according to the mapping table defined in the description of the ObjectType 
class.
A type of any field may be specified later by setFieldType() method."

 

> Node.js apache-ignite-client ComplexObjectType does not deserialize nested 
> objects when the nested type is specified as a ComplexObjectType
> -------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: IGNITE-11013
>                 URL: https://issues.apache.org/jira/browse/IGNITE-11013
>             Project: Ignite
>          Issue Type: Bug
>          Components: thin client
>         Environment: Debian 9, stretch
> "apache-ignite-client": "^1.0.0"
>            Reporter: Thomas Havlik
>            Priority: Minor
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> I am trying to navigate the Node.js client and discovered this oddity. I'm 
> not sure what the design goal of the type system in the JS client is - is the 
> goal to define some sort of default object, or is to define a schema? The 
> object does not serve as a default object in my tests, so I'm wondering why 
> I'm supposed to feed in actual _values_ and not a schema, like with Mongoose. 
> Nested complex types are also not consistently deserialized:
>  
> {code:java}
> // Desired behavior: specify nested ComplexObjectType directly as a member, 
> get deserialized nested object back
> const nest = new ComplexObjectType({ num: 0 });
> const ty = new ComplexObjectType({ foo: "", nest }); 
> // Uncommenting the following line results in the expected value being 
> returned:
> // ty.setFieldType("nest", nest);
> const cache = (await igniteClient.getOrCreateCache("myCache"))
> .setKeyType(ObjectType.PRIMITIVE_TYPE.INTEGER)
> .setValueType(ty);
> await cache.put(1, {
>     foo: "bar",
>     nest: { num: 1 }
> });
> // Expected output:
> // { foo: "bar",
> //   nest: {
> //     num: 1 } }
> //
> // Actual output:
> // { foo: "bar",
> //   nest: BinaryObject }
> console.dir(await cache.get(1));
> // Additionally, not defining 'nest' in the ComplexObjectType and defining it 
> later will throw:
> const nest = new ComplexObjectType({ num: 0 });
> const ty = new ComplexObjectType({ foo: "" }); 
> ty.setFieldType("nest", nest); // -> IgniteClientError: Field "nest" is 
> absent in the complex object type
> {code}
>  
> Honestly, working with the JS library without types is hugely painful, even 
> with the JS doc. If I am encouraged, I would happily move the Node.js client 
> over to Typescript.
>  
> Tom
>  
> p.s. This is my first issue on JIRA. If it's not filed in the correct place 
> or doesn't take the right format - sorry :)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to