orika

Orika ClassCastException in Spring Boot webapp

牧云@^-^@ 提交于 2021-01-27 04:17:08
问题 I'm having a weird ClassCastException while mapping an entity to a DTO with Orika in a sample Spring Boot webapp I'm working on. I get the exception when I attempt to do the mapping on the deployed app in embedded Tomcat, but I can do the mapping just fine in a JUnit test context. This are the relevant classes (they are all very simple): JPA entity: @Entity public class Position { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String name; // getters

Orika ClassCastException in Spring Boot webapp

こ雲淡風輕ζ 提交于 2021-01-27 04:16:12
问题 I'm having a weird ClassCastException while mapping an entity to a DTO with Orika in a sample Spring Boot webapp I'm working on. I get the exception when I attempt to do the mapping on the deployed app in embedded Tomcat, but I can do the mapping just fine in a JUnit test context. This are the relevant classes (they are all very simple): JPA entity: @Entity public class Position { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String name; // getters

BeanUtils 是用 Spring 的还是 Apache 的好?

江枫思渺然 提交于 2020-09-29 05:12:52
来源 | urlify.cn/vUfIry 前言 在我们实际项目开发过程中,我们经常需要将不同的两个对象实例进行属性复制,从而基于源对象的属性信息进行后续操作,而不改变源对象的属性信息,比如DTO数据传输对象和数据对象DO,我们需要将DO对象进行属性复制到DTO,但是对象格式又不一样,所以我们需要编写映射代码将对象中的属性值从一种类型转换成另一种类型。 这种转换最原始的方式就是手动编写大量的 get/set 代码,当然这是我们开发过程不愿意去做的,因为它确实显得很繁琐。为了解决这一痛点,就诞生了一些方便的类库,常用的有 apache的 BeanUtils ,spring的 BeanUtils , Dozer , Orika 等拷贝工具。这篇文章主要介绍 Apache的BeanUtils 与 Spring 的BeanUtils,其他框架后续文章再做介绍 对象拷贝 在具体介绍两种 BeanUtils之前,先来补充一些基础知识。它们两种工具本质上就是对象拷贝工具,而对象拷贝又分为深拷贝和浅拷贝,下面进行详细解释。 什么是浅拷贝和深拷贝 在Java中,除了 基本数据类型 之外,还存在 类的实例对象 这个引用数据类型,而一般使用 “=”号做赋值操作的时候,对于基本数据类型,实际上是拷贝的它的值,但是对于对象而言,其实赋值的只是这个对象的引用,将原对象的引用传递过去

神奇的Scala Macro之旅(四)- BeanBuilder

给你一囗甜甜゛ 提交于 2020-05-02 10:24:20
在Java开发中,经常会有一个需求,将一个 Bean 复制到另外一个 Bean,尤其是在后台分层的场景下,在不同的层之间传递信息,经常需要进行 这样的一个对象复制工作,类似于: val source : PersonSource = ... val dest = new PersonDest() dest.setName( source.getName ) dest.setEmail( source.getEmail ) dest.setAddress( source.getAddress ) ... 因为这样的代码过于冗长,大量的这样的代码,大大的提升了代码的复杂性,不仅工作无趣,而且很容易遗漏,代码可阅读性差。万能的程序员 自然就会发明一个又一个的轮子来解决这个问题: apache BeanUtils dozer:http://dozer.sourceforge.net orika:http://orika-mapper.github.io/ 所有这样的轮子,都包括这样的一些特性: 字段映射。 一般通过同名字段映射,或者使用 annotation 定义Bean间的字段映射。 类型映射。 诸如完成 String -> Int 这样的类型转换。 嵌套映射。 BeanUtils是一个最简单的,通过reflection来实现对象间的映射,这样存在的问题是有很大的反射开销

Orika vs JMapper - how it works and a speed difference - why?

女生的网名这么多〃 提交于 2020-04-09 16:46:53
问题 I have downloaded and testing these two mapping libraries. I wrote a program which has 100000 iterations and maps the beans of the same class: public class IntBean { @JMap private int int1; @JMap private int int2; . . . @JMap private int int10; } Mappers are created BEFORE iterations start: private JMapper jmapper = new JMapper(IntBean.class, IntBean.class); private MapperFactory orikaFactory = new DefaultMapperFactory.Builder().build(); private MapperFacade orikaFacade = null; orikaFactory

Orika vs JMapper - how it works and a speed difference - why?

柔情痞子 提交于 2020-04-09 16:43:47
问题 I have downloaded and testing these two mapping libraries. I wrote a program which has 100000 iterations and maps the beans of the same class: public class IntBean { @JMap private int int1; @JMap private int int2; . . . @JMap private int int10; } Mappers are created BEFORE iterations start: private JMapper jmapper = new JMapper(IntBean.class, IntBean.class); private MapperFactory orikaFactory = new DefaultMapperFactory.Builder().build(); private MapperFacade orikaFacade = null; orikaFactory

Orika - How can I map abstract nested property's fields

跟風遠走 提交于 2020-01-05 09:02:46
问题 Hi I'm having a hard time mapping an abstract nested property's fields. Here I have the test case that explains it better: package com.mycompany.asd; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import ma.glasnost.orika.MapperFactory; import ma.glasnost.orika.MappingException; import ma.glasnost.orika.impl.DefaultMapperFactory; /** * Tests the mapping of abstract nested property's fields */ public class OrikaTest { private MapperFactory mapperFactory; @Before

Orika - How can I map abstract nested property's fields

☆樱花仙子☆ 提交于 2020-01-05 09:02:30
问题 Hi I'm having a hard time mapping an abstract nested property's fields. Here I have the test case that explains it better: package com.mycompany.asd; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import ma.glasnost.orika.MapperFactory; import ma.glasnost.orika.MappingException; import ma.glasnost.orika.impl.DefaultMapperFactory; /** * Tests the mapping of abstract nested property's fields */ public class OrikaTest { private MapperFactory mapperFactory; @Before

Bean 字段复制利器 MapStruct

蹲街弑〆低调 提交于 2019-12-16 11:33:02
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 本文聊一个工具类,MapStruct ,它是一个在 dto,po(do/entity),vo 等这些 pojo 中转换字段的一个工具,在应用中经常有这样的转换,在 spring 和 apache-commons 中也有 BeanUtils 复制,但不够灵活, 我之前也用反射写过一个字段复制 ,这种复制一般来是是很大量的,用反射会使系统的性能降低,有一种更高效的办法就是使用字节码工具类生成这些代码,这时在编译期就把代码弄好了,并且出错也好调试。 除了 MapStruct ,类似的工具还有 Spring 的 BeanUtils ,apachecommons 的 BeanUtils Dozer - Mapper that copies data from one object to another using annotations and API or XML configuration. JMapper - Uses byte code manipulation for lightning-fast mapping. Supports annotations and API or XML configuration. ModelMapper - Intelligent object mapping library

Date format different for two calls using Orika mapper

假如想象 提交于 2019-12-11 08:18:04
问题 I am getting different date formats for two web-service calls using same mapper. By mapper I mean, map:162, ConfigurableMapper (ma.glasnost.orika.impl) The OTB call to get orders i.e. OrdersController#getOrderForUserByCode() is showing the date as "date": "2018-12-22T20:42:31+0000" . My custom call to get orders i.e. IndReportController#createAdvancedOrderSearchReport() is showing the same date as "date": 1545511351000 I am using the same code as OTB to print OrderWsDTO i.e. getDataMapper()