Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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.

share|improve this question
    
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? –  Gerold Broser Nov 26 '14 at 2:44

1 Answer 1

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.

share|improve this answer
    
Thanks @Sebastian I'll give a try –  UtkarshBhavsar Jan 25 at 8:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.