Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any IntelliJ features to map values between two similar objects?

I've been doing a lot of integration towards SOAP services lately. Say I get this object from the SOAP service:

public class ObjectA{
  private String someString;
  private Integer someInteger;
}

For this object I want to make my own representation "ObjectB" which is basically the same but I dont want to expose objects from the WSDL outside my integration artifact.

So then I map between ObjectA and ObjectB. But this is a lot of manual work especially if the objects have many fields. Are there any smart ways in IntelliJ to generate a mapping between two objects?

Thanks

like image 607
oyvind.s Avatar asked Feb 08 '13 13:02

oyvind.s


People also ask

What is the differences viewer in IntelliJ?

The differences viewer shows you differences and similarities between two database objects: Origin and Target. The migration script is generated to make Target equal to Origin. In IntelliJ IDEA, you can compare two database objects of the same type. For example, you can compare two schemas, two tables, or two routines.

How do I compare two databases in IntelliJ IDEA?

In IntelliJ IDEA, you can compare two database objects of the same type. For example, you can compare two schemas, two tables, or two routines. IntelliJ IDEA shows you the differences in the structures of these two objects. For changes, IntelliJ IDEA uses the following color coding.

How to compare two map objects in Java?

@paweloque For Comparing two Map Objects in java, you can add the keys of a map to list and with those 2 lists you can use the methods retainAll() and removeAll() and add them to another common keys list and different keys list. Using the keys of the common list and different list you can iterate through map, using equals you can compare the maps.

What is the difference between Eclipse vs IntelliJ?

Let us look at the key differences between Eclipse vs IntelliJ as below: Generally, Eclipse handles very large and scalable projects faster and efficiently, without consuming much time for indexing the entire IDE project.


1 Answers

You can use the Dozer framework, which is an Object-to-Obejct mapper.

By default it will map by convention, but this can be overridden/customized with a mapping file.

Details here: http://dozer.sourceforge.net/

I've used it before to map use-case specific service payload objects onto re-usable domain objects.

Edit:

MapStruct is a more modern mapping framework. It uses compile-time generation:

like image 161
Jasper Blues Avatar answered Oct 06 '22 17:10

Jasper Blues