Ivo Raemy
asked on
Java class which converts object type to types like Long, Date, Integer
Hello
I am looking for a Java class which converts object type to types like Long, Date, Integer
sincerely
Ivo Raemy
I am looking for a Java class which converts object type to types like Long, Date, Integer
sincerely
Ivo Raemy
Your question doesn't really make sense. Please expand on your requirement
Do you have a String value or something that you are trying to convert to the appropriate type? Do you have input examples of what you are trying to convert. This could help us answer your question.
I have a feeling you need a cast.
Hi,
There is no class that does this for you as such. Although you could create your own.
The methods are available to help you convert objects to the specified class but it depends on what you know already about the class.
You could look at
class.isAssignableFrom
instanceof
Then depending on the class you could attempt to convert it using Integer.parseInt() etc...
Thanks,
Darren
There is no class that does this for you as such. Although you could create your own.
The methods are available to help you convert objects to the specified class but it depends on what you know already about the class.
You could look at
class.isAssignableFrom
instanceof
Then depending on the class you could attempt to convert it using Integer.parseInt() etc...
Thanks,
Darren
Describing the code to a goal that's being guessed at and possibly false is really a waste of time. Describe your GOAL Ivo
ASKER
Hallo
I want to execute a native query and get the values.
I get all numbers in format BigDecimal.
I can do conversions by my Code, However, I am sure that there a better solutions.
Query query = getEntityManager().createN ativeQuery (queryStr) ;
List<Object[]> paquetValidations = query.getResultList();
paquetValidations.forEach( (paquetVal idation) -> {
//convert
Long etudiantId = paquetValidation[0] == null ? null : Long.parseLong(String.valu eOf(paquet Validation [0]));
I want to execute a native query and get the values.
I get all numbers in format BigDecimal.
I can do conversions by my Code, However, I am sure that there a better solutions.
Query query = getEntityManager().createN
List<Object[]> paquetValidations = query.getResultList();
paquetValidations.forEach(
//convert
Long etudiantId = paquetValidation[0] == null ? null : Long.parseLong(String.valu
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello Darren
Thanks for your post.
Il will write my own class.
sincerely
Ivo
Thanks for your post.
Il will write my own class.
sincerely
Ivo
If they're student IDs then you're not likely to be doing arithmetic on them are you - so why not String?
Also JPA supports typed results:
https://docs.oracle.com/javaee/6/api/javax/persistence/EntityManager.html#createNamedQuery(java.lang.String,%20java.lang.Class)
String studentId = paquetValidations[0].toString();
Also JPA supports typed results:
https://docs.oracle.com/javaee/6/api/javax/persistence/EntityManager.html#createNamedQuery(java.lang.String,%20java.lang.Class)