Matthew Henry

Ranch Hand
+ Follow
since Apr 01, 2023
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Matthew Henry

Which note taking app supports to sync or pull data from shared dropbox shared folder link?
7 months ago
Public Sharing:  Does Any Note Sharing App allow sharing entire notebooks or collections with public URLs. This gives anyone with the link access (depending on permissions set). I want to share my entire collection along with search/advanced search for the user, however they should NOT be able to edit or delete my content. Basically read-only access or credentials...Somehow....
7 months ago
Hi,

Can someone help me with the list of good java technology to learn in 2024-2025 so sustain in IT industry for next 5 years

Thank you
7 months ago
Can we have two mapper

package external;

import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

@Mapper
public interface EmployeeMapper1 {
   EmployeeMapper INSTANCE = Mappers.getMapper(EmployeeMapper.class);

   @Mapping(source = "address.addr1", target = "ad1")
   @Mapping(source = "address.addr2", target = "ad2")
   @Mapping(source = "info.age", target = "empInf.ageinnumber")
   @Mapping(source = "info.birth", target = "empInf.birthdate")
   @Mapping(source = "info.dob", target = "empInf.dob")
   @Mapping(source = "training.tr1", target = "t1")
   @Mapping(source = "training.appDTO.appName", target = "appName")
   Employee toEmployee(incoming.EmployeeDTO employeeDTO);

   @InheritInverseConfiguration
   incoming.EmployeeDTO toEmployeeDto(Employee target);
}


package external;

import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

@Mapper
public interface EmployeeMapper2 {

    @Mapping(source = "ad1", target = "address.addr1")
 .....
........
   Employee toEmployee(external.EmployeeDTO2 employeeDTO2);

}
7 months ago
How about Mapstruct ?

Step 1: Add Dependencies to pom.xml

<dependencies>
   <dependency>
       <groupId>org.mapstruct</groupId>
       <artifactId>mapstruct</artifactId>
       <version>1.4.2.Final</version>
   </dependency>
   <dependency>
       <groupId>org.mapstruct</groupId>
       <artifactId>mapstruct-processor</artifactId>
       <version>1.4.2.Final</version>
       <scope>provided</scope>
   </dependency>
   <dependency>
       <groupId>com.fasterxml.jackson.core</groupId>
       <artifactId>jackson-databind</artifactId>
       <version>2.13.3</version>
   </dependency>
</dependencies>

Step 2: Create the Mapper Interface

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

@Mapper
public interface EmployeeMapper {
   EmployeeMapper INSTANCE = Mappers.getMapper(EmployeeMapper.class);

   @Mappings({
       @Mapping(source = "Address.addr1", target = "ad1"),
       @Mapping(source = "Address.addr2", target = "ad2"),
       @Mapping(source = "Info.ageinnumber", target = "EmpInf.ageinnumber"),
       @Mapping(source = "Info.birthdate", target = "EmpInf.birthdate"),
       @Mapping(source = "Info.DOB", target = "EmpInf.DOB"),
       @Mapping(source = "Training.tr1", target = "t1"),
       @Mapping(source = "Training.AppDTO.appName", target = "appName")
   })
   Employee toEmployee(EmployeeDTO source);
}

Step 3: Use the Mapper

import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
   public static void main(String[] args) throws Exception {
       String sourceJson = "{\"Employee\":{\"Address\":{\"addr1\":\"123 Main St\",\"addr2\":\"Apt 4B\",\"addr3\":\"City\"},\"Info\":{\"Age\":30,\"Birth\":\"John Doe\",\"DOB\":\"1994-05-15\",\"Gender\":\"Male\"},\"Training\":{\"tr1\":\"Training 1\",\"tr2\":\"Training 2\",\"AppDTO\":{\"appName\":\"App Name\",\"appId\":\"12345\",\"appPrice\":9.99}}}}";
       ObjectMapper mapper = new ObjectMapper();
       EmployeeDTO source = mapper.readValue(sourceJson, EmployeeDTO.class);
       Employee target = EmployeeMapper.INSTANCE.toEmployee(source);
       System.out.println(target);
   }
}

Step4: Output

Employee{ad1='123 Main St', ad2='Apt 4B', EmpInf=EmployeeInformation{ageinnumber=30, birthdate='John Doe', DOB='1994-05-15'}, t1='Training 1', appName='App Name'}

Add multiple methods:
=========================
import org.mapstruct.Mapper;

@Mapper
public interface EmployeeMapper {

 EmployeeDto toEmployeeDto(Employee source);

 Employee toEmployee(EmployeeDto source);
}

Mapping from Employee to EmployeeDTO:

@Mappings({
   @Mapping(source = "ad1", target = "Address.addr1"),
   @Mapping(source = "ad2", target = "Address.addr2"),
   @Mapping(source = "EmpInf.ageinnumber", target = "Info.Age"),
   @Mapping(source = "EmpInf.birthdate", target = "Info.Birth"),
   @Mapping(source = "EmpInf.DOB", target = "Info.DOB"),
   @Mapping(source = "t1", target = "Training.tr1"),
   @Mapping(source = "appName", target = "Training.AppDTO.appName")
})
EmployeeDTO toEmployeeDTO(Employee source);

Mapping from EmployeeDTO to Employee:

@Mappings({
   @Mapping(source = "Address.addr1", target = "ad1"),
   @Mapping(source = "Address.addr2", target = "ad2"),
   @Mapping(source = "Info.Age", target = "EmpInf.ageinnumber"),
   @Mapping(source = "Info.Birth", target = "EmpInf.birthdate"),
   @Mapping(source = "Info.DOB", target = "EmpInf.DOB"),
   @Mapping(source = "Training.tr1", target = "t1"),
   @Mapping(source = "Training.AppDTO.appName", target = "appName")
})
Employee toEmployee(EmployeeDTO source);



@Mapper
public interface EmployeeMapper {

   EmployeeMapper INSTANCE = Mappers.getMapper(EmployeeMapper.class);

   @Mappings({
       @Mapping(source = "Address.addr1", target = "ad1"),
       @Mapping(source = "Address.addr2", target = "ad2"),
       @Mapping(source = "Info.ageinnumber", target = "EmpInf.ageinnumber"),
       @Mapping(source = "Info.birthdate", target = "EmpInf.birthdate"),
       @Mapping(source = "Info.DOB", target = "EmpInf.DOB"),
       @Mapping(source = "Training.tr1", target = "t1"),
       @Mapping(source = "Training.AppDTO.appName", target = "appName")
   })
   Employee toEmployee(EmployeeDTO source);

   @InheritInverseConfiguration
   EmployeeDTO toEmployeeDto(Employee target);
}
7 months ago
Can we do the above in Mapper instead of doing via code, so that it can be configurable easily ?
7 months ago
Source

public class EmployeeDTO {
   private AddressDTO Address;
   private InfoDTO Info;
   private TrainingDTO Training;
}

public class AddressDTO {
   private String addr1;
   private String addr2;
   private String addr3;
}

public class TrainingDTO {
   private String tr1;
   private String tr2;
   private AppDTO AppDTO;
}

public class AppDTO {
   private String appName;
   private String appId;
   private double appPrice;
}

Target

Target

public class Employee {
   private String ad1;
   private String ad2;
   private EmployeeInformation EmpInf;
   private String t1;
   private String appName;
}

public class EmployeeInformation {
   private int ageinnumber;
   private String birthdate;
   private String DOB;

}
7 months ago
Incoming JSON



External JSON to be sent for third party

7 months ago
Hi,

Objective: Source Object and Target Object structure and property are different

I have an incoming request JSON as

Employee -> Address (addr1, addr2, addr3), Info (Age, Birth, DOB, Gender), Training (tr1, tr2, AppDTO)
AppDTO -> appName, appId, appPrice

I need to call a third party API which accepts the following JSON

Employee -> ad1, ad2, EmpInf (ageinnumber, birthdate, DOB), t1, appName

Question:

I have created two DTOs - EmployeeDTO in request package and EmployeeDTO
in external package. I tried with @JSONIgnore and @JSONProperty in target DTO in
external package but couldn't achieve it as above seems to be complex. Even tried with DOT . but doesn't work as expected. Reason (Cannot use both JSONIgnore and JSONProperty at the same time)

Example, mapping t1, appName is more complex

Can someone please kindly share code how to achieve this with code? I'm using BeanConverter to convert
the source to target DTO and trying to achieve via JSONIgnore and @JSONProperty

Please help me on how to achieve using JSONIgnore and JSONProperty and any other alternate solution with mapper to resolve this.

Please help me with some working code references as well if possible for solve complex conversions.

Thank you.

7 months ago
Thank you and will go with Jackson for mapping with Java.
9 months ago
Is JSON-B is better than Jackson ?
9 months ago
Which mapper open source library is recommended or Top 2 in Java for the following?

1. Send same payload with different value object based on each client
2. Send different payload json based on each client
9 months ago
Please let me know if it is possible to debug Java AWS Lambda (serverless framework) in Any IDE.

I want to locally debug before testing on AWS Cloud....

Please kindly help me and struggling for more than a week ...
10 months ago
Hi,

What are the debugging tools available in OpenJDK - Debugging Tools like VisualVM for JDK 1.8

Thanks
1 year ago