Thank you for the answer!

Perhaps maybe we should specify the list of collection implementations and
add an example to the documentation? I think it will be helpful.

вт, 14 февр. 2023 г. в 11:24, Николай Ижиков <nizhi...@apache.org>:

> > Thanks for your question! Could you please provide doc references where
> you found that it should be possible?
>
>
> https://ignite.apache.org/docs/latest/key-value-api/binary-objects#enabling-binary-mode-for-caches
>
> > The following classes are never converted (e.g., the toBinary(Object) method
> returns the original object, and instances of these classes are stored
> without changes):
> …
> > Maps, collections and arrays of objects (but the objects inside them
> are reconverted if they are binary)
>
>
>
>
> 14 февр. 2023 г., в 11:22, Николай Ижиков <nizhikov....@gmail.com>
> написал(а):
>
> Hello.
>
> The trick here is the following line
>
> > car.setInspirations(List.of(new Car(), new Car()));
>
> Ignite serialize as a binary collection only *some* implementation of List
> interface.
> Others serialized using standard java serialization.
>
> I rewrite your code and now it’s working as expected:
>
> ```
>
> public class SimpleTest extends GridCommonAbstractTest {
>     @Test
>     public void testGetCarInspirationsWithBinaryapi() throws Exception {
>         Ignite ignite = startGrid(0);
>
>         Car car = new Car();
>         car.setName("carname");
>         car.setWeight(BigDecimal.ONE);
>
>         List<Car> inspirations = new ArrayList<>();
>
>         inspirations.add(new Car());
>         inspirations.add(new Car());
>
>         car.setInspirations(inspirations);
>
>         ignite.getOrCreateCache("Sample").put("carname", car);
>
>         IgniteCache<String, BinaryObject> binaryCarCache = 
> ignite.getOrCreateCache("Sample").withKeepBinary();
>
>         List<BinaryObject> carInspirations = 
> binaryCarCache.get("carname").field("inspirations");
>
>         assertEquals(2, carInspirations.size());
>         assertTrue(carInspirations.get(0) instanceof BinaryObject);
>
>         BinaryObject binaryCar = carInspirations.get(0);
>
>         assertNull(binaryCar.field("name"));
>     }
>
>     public class Car implements Serializable {
>         private String name;
>         private List<Car> inspirations;
>         private BigDecimal weight;
>
>         public String getName() {
>             return name;
>         }
>
>         public void setName(String name) {
>             this.name = name;
>         }
>
>         public List<Car> getInspirations() {
>             return inspirations;
>         }
>
>         public void setInspirations(List<Car> inspirations) {
>             this.inspirations = inspirations;
>         }
>
>         public BigDecimal getWeight() {
>             return weight;
>         }
>
>         public void setWeight(BigDecimal weight) {
>             this.weight = weight;
>         }
>     }
> }
>
> ```
>
>
>
> 14 февр. 2023 г., в 09:07, Mikhail Pochatkin <m.a.pochat...@gmail.com>
> написал(а):
>
> Hi, Dinakar.
>
> Thanks for your question! Could you please provide doc references where
> you found that it should be possible?
>
> вт, 14 февр. 2023 г. в 07:18, Dinakar Devineni <dina....@gmail.com>:
>
>> Hi,
>>
>>
>>
>> Appreciate  some help, to  understand  why is  this  failing  and  how
>> to correct this.
>>
>>
>>
>> Trying to  read  a  list of  binary  objects form a  composite  data
>> structure
>>
>> Here  is the  sample code.  As  per  ignite  documentation this  should
>> be  possible.
>>
>>
>>
>>
>>
>> @Getter
>>
>> @Setter
>>
>> Public class Car implements Serializable {
>>
>> private String name;
>>
>> private List<Car> inspirations;
>>
>> private BigDecimal weight;
>>
>> }
>>
>>
>>
>>
>>
>> @Test
>>
>> Public void testGetCarInspirationsWith Binaryapi(){
>>
>>
>>
>> Ignite ignite = Ignition.start();
>>
>>
>>
>> Car car = new Car();
>>
>> car.setName(“carname”);
>>
>> car.setWeight(BigDecimal.ONE);
>>
>> car.setInspirations(List.of(new Car(), new Car()));
>>
>>
>>
>>
>>
>> ignite.getOrCreateCache(“Sample”).put("carname”, car);
>>
>> IgniteCache<String, BinaryObject> binaryCarCache =
>> ignite.getOrCreateCache(“Sample”).withKeepBinary();
>>
>>
>>
>> // this  line is not  returning list  of  binary objects, rather
>> returning desrialize  objects
>>
>> List<BinaryObject> carInspirations =
>> binaryCache.get(“carname”).field(“inspirations”);
>>
>>
>>
>> }
>>
>>
>>
>>
>>
>> Tech
>>
>> Java 11
>>
>> Ignite 2.14
>>
>>
>>
>>
>>
>> Thanks
>>
>> D
>>
>>
>>
>
>
> --
> best regards,
> Pochatkin Mikhail.
>
>
>
>

-- 
best regards,
Pochatkin Mikhail.

Reply via email to