commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hodges, Jonathan (NBC Universal)" <Jonathan.Hod...@nbcuni.com>
Subject ValueSuppressionStrategy in 0.7
Date Sat, 19 Nov 2005 00:17:58 GMT
Hello,

I was wondering if anyone noticed that changing the default behavior of
suppressing the expression of all empty attributes doesn't seem to be
working properly.  It is very possible that I did some thing wrong, but I
don't believe so based on the following documentation in the 0.7 Release
notes:

'Betwixt now (by default) suppresses the expression of all empty attributes.
The old behaviour can be restored by setting the ValueSuppressionStrategy of
the BindingConfiguration used by the writer to
ValueSuppressionStrategy.ALLOW_ALL_VALUES'

Here is my code:

        StringWriter outputWriter = new StringWriter();
        BeanWriter writer = new BeanWriter(outputWriter);
    	
 
writer.getXMLIntrospector().getConfiguration().setAttributeNameMapper(new
DecapitalizeNameMapper());

 
writer.getXMLIntrospector().getConfiguration().setElementNameMapper(new
DecapitalizeNameMapper());

 
writer.getBindingConfiguration().setValueSuppressionStrategy(ValueSuppressio
nStrategy.ALLOW_ALL_VALUES);
        writer.getBindingConfiguration().setMapIDs(false); 
        
 
writer.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(tr
ue);
        writer.enablePrettyPrint();
        writer.setWriteEmptyElements(true);

        Geocoder geocoder = new Geocoder();
        Result result = new Result();
        result.setFips(2);
        result.setToken("token");
        result.setZip(35244);
        geocoder.setResult(result);
        Diagnostic diagnostic = new Diagnostic();
        diagnostic.setInputaddress("input address");
        diagnostic.setInputString("input string ");
        diagnostic.setLat(123);
        diagnostic.setLocation("location");
        diagnostic.setLon(321);
        diagnostic.setStatus("status");
        diagnostic.setVerbclause("verbclause");
        geocoder.setDiagnostic(diagnostic);
        
        // write out the bean
        writer.write(geocoder);
        System.out.println(outputWriter.toString());


Geocoder.java:

public class Geocoder {

	private Diagnostic diagnostic = null;
	private Result result = null;
	
	public Diagnostic getDiagnostic() {
		return diagnostic;
	}
	public void setDiagnostic(Diagnostic diagnostic) {
		this.diagnostic = diagnostic;
	}
	public Result getResult() {
		return result;
	}
	public void setResult(Result result) {
		this.result = result;
	}
	
}


Diagnostic.java:

public class Diagnostic {

	private String inputString = null;
	private String status = null;
	private int lat;
	private int lon;
	private String inputaddress = null;
	private String verbclause = null;
	private String location = null;
	
	public String getInputaddress() {
		return inputaddress;
	}
	public void setInputaddress(String inputaddress) {
		this.inputaddress = inputaddress;
	}
	public String getInputString() {
		return inputString;
	}
	public void setInputString(String inputString) {
		this.inputString = inputString;
	}
	public int getLat() {
		return lat;
	}
	public void setLat(int lat) {
		this.lat = lat;
	}
	public String getLocation() {
		return location;
	}
	public void setLocation(String location) {
		this.location = location;
	}
	public int getLon() {
		return lon;
	}
	public void setLon(int lon) {
		this.lon = lon;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getVerbclause() {
		return verbclause;
	}
	public void setVerbclause(String verbclause) {
		this.verbclause = verbclause;
	}
	
}


Result.java:



	private int fips;
	private int zip;
	private String token = null;
	
	public int getFips() {
		return fips;
	}
	public void setFips(int fips) {
		this.fips = fips;
	}
	public String getToken() {
		return token;
	}
	public void setToken(String token) {
		this.token = token;
	}
	public int getZip() {
		return zip;
	}
	public void setZip(int zip) {
		this.zip = zip;
	}
	
}


The XML output is:


  <geocoder>
    <diagnostic/>
    <result/>
  </geocoder>


I would have expected all of the attributes to be returned, yet they do not.
If I run the same code with the 0.6 version it works correctly.

Any ideas,

Jonathan

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message