-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS customise generated name #50
Comments
Code in question is in |
I was thinking that an annotation might be the way to go.
In this case the id attribute for client would be serialized as "id" instead of "com.test.domain.Client" Or possibly a better place might be on the Client entity itself.
|
Ok, use of annotations sounds reasonable enough, and should be accessible. A simple unit test or sample classes would be useful. I am pretty good at merging contributions as well. :) |
@jackmatt2 @cowtowncoder While custom names would be nice, there is currently a way to use the id's actual attribute name instead of the full package and class name. If the Hibernate session is still open when the bean is serialized the real attribute name will be used. If the session is closed, the package and class name are used instead. |
First try for identifier field (that annotated with @id) If Id field present, id field name used ad key instead of class name.
Hello Guys. |
It is worth noting that the HibernateSerializer uses the actual name of the id property if the session is still open, or the hibernate mapping is passed to the Hibernate4Module constructor. Still, it would be nice if the Serializer could infer this information automatically in all cases. |
At this point, what I really need is a unit test that shows expected behavior; solutions are only useful once problem is shown. |
I don't have time to write a full test, but I can clarify the behaviour I would expect, and that @jackmatt2 probably means when he says "use the property from the java bean": Given an entity
or an entity
or an entity
where
the following should pass:
|
@bedag-moo Perhaps someone can find time to work on this, either on writing the test, or working using other means to resolve it. I do not use Hibernate and my time is spread across many jackson modules, so this will not be high priority. |
It would appear that this actually does work, as long as you instantiate the Hibernate4Module with the hibernate mappings: http://stackoverflow.com/questions/21472926/override-id-name-generated-by-jackson-datatype-hibernate What I can't figure out is how to get a handle on the LocalSessionFactoryBean in a spring boot app in order to provide the mappings. Any ideas? |
Oh, nevermind, I realized I can cast the sessionFactory to "Mappings" and it works. I used this technique to get the sessionFactory in spring boot - http://stackoverflow.com/a/33881946/228369 |
It would be good if Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS would let you customise the generated name, or at least use the name from the java bean.
Currently it is serializing using full package and class name:
"client":{"com.test.domain.Client":1}
I want it to use the id instead (which is the name of the attribute in the hibernate entity):
"client":{"id":1}
Maybe there is a way around this but I can't find any.
The text was updated successfully, but these errors were encountered: