1
\$\begingroup\$

I have ChannelWrapper and Channel Value Object. I want to convert each and every field of ChannelWrapper to Channel Value Object.

public class ChannelWrapper extends BaseWrapper implements APIWrapper<Channel>,
 APIUnwrapper<Channel> {
 @XmlElement
 private Long id;
 @XmlElement
 private User user;
 @XmlElement
 private Tenant tenant;
// Getter Setters
 @Override
 public Channel unwrap(HttpServletRequest arg0, ApplicationContext arg1) {
 // TODO Auto-generated method stub
 return null;
 }
 @Override
 public void wrapDetails(Channel model, HttpServletRequest request) {
 this.id = model.getId();
 this.user = model.getUser();
 this.tenant = model.getTenant();
 }
 @Override
 public void wrapSummary(Channel model, HttpServletRequest request) {
 wrapDetails(model, request);
}

Channel Value Object:

public class Channel {
 private Long id;
 private User user;
 private Tenant tenant;
 //getter setters }

Converter:

Channel channel = new Channel();
channel.setId(channelWrapper.getId());
channel.setUser(channelWrapper.getUser());
channel.setTenant(tenant);

Is this the best way to create a converter?

Any other general comments are appreciated.

TheCoffeeCup
9,5164 gold badges38 silver badges96 bronze badges
asked Nov 24, 2014 at 13:39
\$\endgroup\$
1
  • \$\begingroup\$ I'm sorry but I don't get your point. You have a wrapper, a.k.a. Adapter, for a Channel, ChannelWrapper. Now you'd like to wrap this wrapper into another wrapper (or converter as you call it) such leading to a ChannelWrapperWrapper or ChannelWrapperAdapter. And you'd like to call it ChannelValueObject? Isn't that a bit confusing and/or over-engineered? \$\endgroup\$ Commented Nov 26, 2014 at 2:44

1 Answer 1

3
\$\begingroup\$

Since both classes have the same getters and setters this can most easily be achieved using apache commons beanutils:

Channel channel = new Channel();
BeanUtils.copyProperties(channel, channelWrapper);

if you have more complex requirements (e.g. different property names or types), I would recommend dozer.

answered Jan 25, 2015 at 8:53
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.