fasterXML BeanSerializerBase vs codehaus - fasterxml

I am trying to replace
org.codehaus.jackson.map.ser.std.BeanSerializerBase
with
com.fasterxml.jackson.databind.ser.std.BeanSerializerBase
and not sure how, as the first one has only one abstract method serialize(...) and the new fasterXML has 6 abstract methods.
Whats to best way to approach this change.
One related class that I see is Class StdSerializer<T>
Many thanks.

Related

How to order/sort my collections / relationships?

I've just started using Jhipster for a simple project with a very simple datamodel (so far).
I have a question regarding the generated code for the one-to-many relationship:
Is it possible to generate with List instead of a Set, so I can have my child-items ordered?
If no, what is the best solution to solve my problem? I see 2 ways:
Change the generated code manually to use a List and then use liquibase (mvn liquibase:diff) to update my database ?
Have an attribute on the child-item to handle the order ?
What is the best way to handle the "problem" ?
Best regards
Martin Elkkjær
You can use the Spring #OrderBy annotation to sort your sets by the child entity. See http://www.objectdb.com/api/java/jpa/OrderBy
#Entity
public class Person {
...
#OrderBy("zipcode.zip, zipcode.plusFour")
public Set<Address> getResidences() {...};
...
}
I'd also recommend the following blog that explains how Sets/Lists differ for Hibernate and JPA: https://vladmihalcea.com/hibernate-facts-favoring-sets-vs-bags/ (where I found the answer originally)

JAXB how to remove anything from JDefinedClass

i am using jaxb to generate code from an xsd.
The generated code contains a lot of annotations; for classes and fields.
I am trying to use com.sun.tools.internal.xjc.Plugin to modify the generated code.
In the plugin run() method we are given an Outline class from which we can get ClassOutline. ClassOutline has an JDefinedClass final member which has the info about actual class which will be generated.
If i want to add anything, there are apis in JDefinedClass which can be used. But if i want to remove something, there is no way.
e.g. i cannot clear annotations, because the JDefinedClass.annotations() method returns an UnmodifiableCollection. so i cannot clear it or remove anything from it.
i tried to create another JDefinedClass by invoking the _class method but the ClassOutline.implClass variable is final, so i cannot set it.
how to get a JDefinedClass which does not have any annotations?
is there another phase of code generation which i can trap into to really control the generation of JDefinedClass?
The code model is, indeed mostly "write only". But, speaking of annotations, you have probably missed the methods like com.sun.codemodel.JDefinedClass.removeAnnotation(JAnnotationUse) and com.sun.codemodel.JMethod.removeAnnotation(JAnnotationUse) (implemented from com.sun.codemodel.JAnnotatable.removeAnnotation(JAnnotationUse)).
So they're there. You can remove annotations with the normal CodeModel API.
As I can see, you can also remove fields and methods from classes. So what exactly are you missing?
JDefinedClass.annotations() It return an unmodifiable collection object and you cannot modify them.
So work around for this, you can restrict annotation addition/deletion at class and field level before building JCodeModel.
You need to create a custom Jackson2Annotator class which extends Jackson2Annotator and override their methods according to your requirement.
Following are few methods which are being used for specific type of annotation property:
propertyOrder(OTB JsonPropertyOrder)
propertyInclusion(OTB JsonInclude)
propertyField(can be used for custom defined annotation at field level)
More you can discover by looking Jackson2Annotator class what fit into your need.

How to really define what a "helper" is?

How can we really say "Here it is, the class I just developed is a helper!"
Would the class have some special criteria? I have a class in Java that exporta my JTables into CVS Files. Is it a helper? I also use a class to validate my forms. Is it a helper?
I hear this term often, but I realize that I don't really know what is it.
I don't think there is a 'textbook' definition of what a helper is, but I think most people would define a helper Class as one that makes no sense on its own - in other words, a Class whose whole purpose of existence it to 'help' make some operation on another class easier to do.
For example, if you create a class that follows the 'Adapter' pattern (i.e. it wraps an object of type 'foo' and lets it be used where normally you can only use type 'bar',) I think that adapter class could loosely be called a 'helper' class as well.
A helper class is a class that is used only by another class to complete a function. Thus, the helper has no right or need to be public, and is only created as being private.
For example, Private Class B helps public class A complete a set of tasks, A is calling on B and is of no use on its own.
For example (just a quick write-up, not tested)
private int newInt(String str)
{
test = Integer.parseInt(str);
return test;
}
and it could be called by:
public int transformation(String str)
{
return newInt(str);
}
This of course would be a class of its own, which would have to be called in your main class.
From some of the quick research I did, and my own personal experience when dealing with helper classes (.Net and Java), a helper class, is a class that provides functionality that is not actually relevant to the code one is developing, but rather provides some boilerplate work, such as casting, converting datatypes, or performing some common mathematical functions, for instance.
Such code can be generally reused in other projects, to further facilitate work being done.
Not everything helps should be a helper, a class wouldn't even exist if it didn't 'help' something. Usually helper classes offer shortcuts, like sql helpers. I think they should be something spesific and contain a group of relevant shortcut functions.
I think a "helper" class is a class which has been created only to support another classes on their functions.
There are a lot of cases where you need to create a "helper" class to put on it some methods that they do some functions. Some examples would be a class that have methods to calculate holidays on a year or transform some fields or formats in another.
Another example could be when you have to develop an app that it has a progress bar. You can create a "helper" class only for manage the progress bar (setting texts, calculating times, providing estimations...).
If you divide your app on layers (GUI, Business, DAO, etc.), it's interesting to have some "helper" or "utility" class (or classes) to do some tasks that you need to do but that they don't belong to GUI, business or DAO (Data Access Objects) layers explicitly. In this case, you could have an utility class for each layer and put inside the auxiliary methods that you need.

xceed Propertygrid - how to use a property collection

I try to use the great propertygrid from exceed.wpftoolkit but I have to problems based on the application I have to create.
First I didn't know at compile time the number of properties the grid has to show. So I couldn't use a simple class with properties/attributes and annotations as datacontext or source for the grid, I need a list or dictionary in which I place a number of grid properties at runtime.
I google for several hours and try to find an example in the sample folders of the toolkit sources but nothing has help me.
Second problem or apply is to replace the usage of annotations in the property class. I need to create the properties at runtime and place the propertyeditor and annotation settings at runtime to the property.
Could anybody help me with some simple examples or good places to look for. I believe the propertygrid is very powerful and could do this.
You need to create a class that implements the ICustomTypeDescriptor interface to provide all the PropertyDescriptor instances that represent your dynamic properties.
After that you can set an instance of the class that implements the ICustomTypeDescriptor interfaces as SelectedObject to the PropertyGrid.
You can find an example here.

how can i show a conroller class in class_diagram? and what roles does it have?

i can't understand how a controller class can exist inside of a class diagram?
and if it is possible what roles does it have and how can i detect such a thing?
what design patterns can i find about deploying controller classes in class_diagrams?
can any body define a controller class for me i think its kind a redundant.
//this part is not a part of my question
//it was a quality check and i have to increase my question characters
//i don't know this is enough or not
//so first try
A controller is just like a regular class in your class diagram. To explicitly say that it is a controller, you can add a stereotype, like <<Controller>> for the controller class.
I found some examples on the internet here, and here, and I am sure there are many more out there.

Resources