Real time scenario for a custom entity provider [closed] - java

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
In JAX-RS there is an option to define a custom entity provider(message body workers or message body readers and writers) so that you can map a java bean to MIME type (say application/myBean).
Are there any scenario where one would need it?

One reason for defining custom Media Types is defining tighter contracts. For instance using the header Accept: application/vnd.com.example.customer+xml defines on protocol-level that a list of orders won't be accepted. This is not possible with using application/xml.
If you want to use custom Media Types you need custom providers for serialization.
There is a long going debate if this is a good idea or not.

Related

Is it a good practice to have POJO settings class as a bean? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I have a simple POJO class with few fields. This POJO serves the role of settings and it is passed to one method which actually executes some logic. Fields from this POJO are taken from the app.properties and they will not change.
What is a better pratice?
Create this POJO every time we want to call the method which needs it.
Make it a singleton bean, create it once and then autowire it?
Spring Boot provides the #ConfigurationProperties mechanism specifically to automate this for you. In general, it's best to avoid direct dependencies on MyServiceProperties and to do the injection in an #Bean method, but the MyServiceProperties instance is available as a context bean.

What is the best way to name a class that does some processing only after post construct? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have a ValueObject and a builder class in Java . For example Request.java and RequestBuilder.java. RequestBuilder is used to build Request object. When the Request object is constructed I want to call some business logic which has to to be in separate file. This Request object is constructed at many places in the code and I want to call the businness logic( sets/updates some values on Request object) What is the best way to do and name that class? Would RequestFactory.java be appropriate name for it?
Name it something like RequestProcessor. Don't forget to restrict access to its constructor(s) (private, protected or package which best suits your needs). RequestFactory is more appropriate alternative name for your RequestBuilder.

Which Design pattern should i use to maintain pre initialized set of objects? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have some pre initialized objects of some class. These objects are heavy weight objects and each correspond to some configuration options specified by user. There will be exactly one instance corresponding to one configuration and same will be used every time.
My question is, which design pattern suits best to handle this kind of situation?
Most likely a Flyweight is what you are looking for. https://en.wikipedia.org/wiki/Flyweight_pattern
This can be used for pre-initialise heavy weight objects and reuse them.

Ways to pass an ArrayList with socket [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
What is the best way to pass an ArrayList<Object> from server to client?
After i have to put my ArrayList in a JTable.
You have to serialize it when you write to the socket and deserialize when you read from the socket.
Ultimately you're sending Strings on the wire. Transport doesn't know or care anything about objects on either end of the conversation. TCP/IP is language independent.
You have many choices to choose from:
Java Serializable - this means sending byte code on the wire.
XML. You can use JAXB.
JSON. You can use Jackson.
Custom protocol of your own design.

Where to use #NamedQueries [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am using #NamedQueries but not sure what is the best way to use it.
Use it above entity class
Use it above DAO class
Create One NamedQueriesFactory class which will have centralized named queries for all Entity
Any other better way.
i good way would be to put all of them in an xml file which is used a lot. this externalizes your queries and gives you the freedom of just sending over this xml file to some DBA for easier analysis later on.
2 (Dao) and 3 (factory class) are not real options, assuming that those are not also entities, because according documentation:
The NamedQueries annotation can be applied to an entity or mapped
superclass.
That leaves as with 1 (entity) and 4 (mapped superclass). I would locate queries by return type and/or main entity accessed in query. Because mapped superclass cannot be returned from the JPQL queries, answer would be 1 (entity).

Categories

Resources