Using annotations to remap fields when deserializing BinaryObjects

classic Classic list List threaded Threaded
3 messages Options
DanieleBosetti DanieleBosetti
Reply | Threaded
Open this post in threaded view
|

Using annotations to remap fields when deserializing BinaryObjects

Hi,

is it possible to deserialize cache entries to Java objects, and specify
field names mapping using annotations?

In example, let's say cache entries follow a "with-dashes" naming
convention:

binaryObject.toString() = "domain.User[id=... idHash=... user-name=Paul ]"

And I deserialize it with

User user = binaryObject.deserialize();

class User {
  *@MapToFieldName{"user-name"}*
  private String name;
}


What can we put in place of "MapToFieldName" so that the "user-name" value
from the binary object is placed into the "name" field?

(I know the @QuerySqlField annotation, but that maps sql field names to
cache field names)


thanks!





--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Stanislav Lukyanov Stanislav Lukyanov
Reply | Threaded
Open this post in threaded view
|

RE: Using annotations to remap fields when deserializing BinaryObjects

Hi,

 

Nope, it doesn’t work like that.

Names of fields in the Java class are always the same as the names of the fields in BinaryObject.

 

Frankly, I don’t really see a strong use case for the customization you’re asking for.

If it is just to support different naming conventions in different places (Java, SQL, other clients)

then I’d much more preferred the simplicity to flexibility and forced a single naming across all context.

 

Stan

 

From: [hidden email]
Sent: 11 октября 2018 г. 12:31
To: [hidden email]
Subject: Using annotations to remap fields when deserializing BinaryObjects

 

Hi,

 

is it possible to deserialize cache entries to Java objects, and specify

field names mapping using annotations?

 

In example, let's say cache entries follow a "with-dashes" naming

convention:

 

binaryObject.toString() = "domain.User[id=... idHash=... user-name=Paul ]"

 

And I deserialize it with

 

User user = binaryObject.deserialize();

 

class User {

  *@MapToFieldName{"user-name"}*

  private String name;

}

 

 

What can we put in place of "MapToFieldName" so that the "user-name" value

from the binary object is placed into the "name" field?

 

(I know the @QuerySqlField annotation, but that maps sql field names to

cache field names)

 

 

thanks!

 

 

 

 

 

--

Sent from: http://apache-ignite-users.70518.x6.nabble.com/

 

DanieleBosetti DanieleBosetti
Reply | Threaded
Open this post in threaded view
|

RE: Using annotations to remap fields when deserializing BinaryObjects

Hi,

Well one (weak) reason is that somebody else could already have put data to
a cache using the "dash" convention, and in that case we are unable to
retrieve this data (eg. how can we (automatically) deserialize the
"user-name" field?)

also, allowing this mapping would be in line with hibernate/jpa
(java.persistence.Column annotation); where you can have whatever naming
convention for database tables, and can then freely map to client pojos (DB
data comes first, client pojo-s come later).


anyway; what you say makes perfectly sense so, thanks for clarifying this!
(and we'll go with the single name convention).




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/