Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping to Map #74

Open
khirschmann opened this issue Oct 12, 2017 · 2 comments
Open

Mapping to Map #74

khirschmann opened this issue Oct 12, 2017 · 2 comments

Comments

@khirschmann
Copy link

When mapping multiple fields to a map AND one of those fields is null all members listed before this field in class are lost (map is set to null).

`public class Source {

@JMap("map")
private String id;
@JMap("map")
private Integer quantity;
@JMap("map")
private Date purchase;


public String getId() {
	return id;
}
public void setId(String id) {
	this.id = id;
}
public Integer getQuantity() {
	return quantity;
}
public void setQuantity(Integer quantity) {
	this.quantity = quantity;
}
public Date getPurchase() {
	return purchase;
}
public void setPurchase(Date purchase) {
	this.purchase = purchase;
}


@JMapConversion(from = { "id", "quantity", "purchase" }, to = "map", type = Type.DYNAMIC)
public static String toAttributeConversion() {
	return " ${destination} = (${destination} != null ? ${destination} : new java.util.HashMap());"			
			+ " System.out.println(\"Converting: \" + \"${source.name}\"); "				
			+ " ${destination}.put(\"${source.name}\", ${source}); "
			+ " return ${destination}; ";
}

}

public class Destination {

private HashMap<String, Object> map;

public HashMap<String, Object> getMap() {
	return map;
}

public void setMap(HashMap<String, Object> map) {
	this.map = map;
}

}

public class Main {

public static void main(String[] args) {
	Source s = new Source();
	s.setId("Id");
	s.setPurchase(new Date());
	
	JMapper<Destination, Source> mapper = new JMapper<Destination, Source>(Destination.class, Source.class);
	Destination d = mapper.getDestination(s);
	System.out.println(d.getMap().toString());

}

}
`
Output:
Converting: id
Converting: purchase
{purchase=Thu Oct 12 14:04:53 CEST 2017}

Perhaps that is the wrong way to do it?

Thx for your help.
Kevin

@avurro
Copy link
Member

avurro commented Oct 12, 2017

Hi @khirschmann,

I need to do a test, let you know as soon as possible

@mdowsian
Copy link

mdowsian commented Dec 7, 2023

Hi @khirschmann,

I need to do a test, let you know as soon as possible

Have you done this test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants