I am trying to get an XML output from a restEasy service. And its working fine. The problem is i am not able to see elements which dont have any values.
I used #xmlElement in domain class wherever necessary. In Json response, i can see elements with null values.This is not working with XML. For Example:
JSON Response:
"chemStructure": {
"inchi": null,
"inchiKey": null,
"smiles": null,
"iupac": null,
"imageUri": null,
"notation": null
}
XML Response:
I want to see atleast the elemenst with empty tags
By default JAXB (which is the default binding layer for JAX-RS implementations such as RESTEasy) will not marshal null values. You can change this behaviour by specifying the nillable setting on #XmlElement.
#XmlElement(nillable=true)
private String imageUri;
Then a null value will be represented in XML with the xsi:nil attribute.
<imageUri xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
For More Information
http://blog.bdoughan.com/2012/04/binding-to-json-xml-handling-null.html
Related
I need to write a dynamic Attribute name instead of hardcode of Name attribute in dataweave 2.0 mulesoft 4 in anypointstudio
<?xml version="1.0" encoding="UTF-8"?>
<iGoApplicationData>
<UserData>
<Data Name="UpdateUserProfile">True</Data>
<Data Name="Action">??</Data>
</iGoApplicationData>
So in order to generate an XML like yours the DW structure will look like
{
iGoApplicationData: {
UserData: {
Data #(Name: payload.foo): "True",
Data #((var.attributeName): "Action"): "??"
}
}
}
So in this example I show how to specify a value in the attribute or a dynamic attribute name. For the dynamic attribute value just type the expression on the value side of the attribute (the part that goes after the :)
For dynamic attribute name you need to wrap the expression between parenthesis. When the name is wrapped between parenthesis it is considered dynamic. This applies to object keys and attributes names
I am trying to compare two jsons, expected and the API Response using Javers, as part of testing. I want the comparison to exclude the ID parameters that are dynamically generated by response.
My VO is like
public class expectedResponse{
#DiffIgnore
private String id;
private String name;
}
Both my expectedResponse- which is read from excel file and the actual response from API are deserialized into this format and then both the responses are compared.
JsonNode expectedOutput = mapper.readTree(expected.toString());
JsonNode apiResponse = mapper.readTree(actual.toString());
diff=javers.compare(expectedOutput, apiResponse);
But this comparison doesn't exclude/ignore the ID field. Any Idea how I can get it to work? I want only the ID field excluded in comparison results, diff in name should be listed.
Also question 2> I am trying to list the changes from diff
if (diff.hasChanges())
{
List<ValueChange> changes=diff.getChangesByType(ValueChange.class);
for (ValueChange change : changes)
{
logger.info(change.getPropertyName()+ "||" +change.getLeft().toString() + "||" +change.getRight().toString());
change.getPropertyName()- doesnt print the property's name but simply prints "_value" as its value.
Can you pls help in identifying what is going wrong with the code and how can I get this fixed? I am not finding much useful documentations about Javers anywhere in google. Any help is appreciated.
You should compare you domain object instead of object with JsonNode class, look that #DiffIgnore annotation is present only in your domain class and there is no connection between JsonNode and ExpectedResponse, thats why Javers doesn't know to ignore this field.
To summarise, your code should looks like this:
ExpectedResponse expectedOutput = ...
ExpectedResponse apiResponse = ...
diff=javers.compare(expectedOutput, apiResponse);
I have created a multifield custom widget having two fields with names ./urlLink and ./urlText.
Now i m trying to fetch the values from widget into the component's jsp with following code
String property = properties.get("./urlLink",String[].class);
for(String value: property ) {
out.print(value);
}
out.print(property);
But i am not able to get its value instead i m getting error.
If you're getting a property and it contains a string value, you need to use the method getString() - that way when you have the property, you can set the string to the value by doing something like this:
Property property = properties.get("./urlLink",String.class);
String value = property.getString();
Just a side note, if your return is supposed to be a string array, your type that you're putting the values in should be a string array.
String[] value
Check out the documentation on day.com for Properties and getting the values inside them.
Looks like a typo: you don't prefix a property name with .\ when accessing it.
My guess is you got a NullPointerException, right? That's because there's no ./urlLink property in the value map (properties). You should check against that anyway (so that it's not thrown on a fresh page with no content).
If that doesn't help -- double check that you have the properties in the content (call your page with .xml or .infinite.json extensions, and then double check if you can read them as plain strings (you should be able to -- CRX does some magic, smart type conversions).
It's good to register custom xtype as :
// registering the custom widget with the name dualfield
CQ.Ext.reg("dualfield", CQ.Ext.form.DualField);
Then u can easily fetch the value as :
String[] data = properties.get("multi",String[].class);
Here multi is the name of widget having multifield as xtype
I'm working on a new application and i need to make a messages interface with lookup, using the key to find the value (like ConstantsWithLookup, but capable to receive parameters). I have being investigating Dictionary class functionality but it lacks message customization through parameters.
With ConstantsWithLookup i can make the following:
myConstantsWithLookupInterface.getString("key");
and get something like:
Field must be filled with numbers
But i need to do this:
myMessagesWithLookupInterface.getString("key", "param1", "param2",...);
and get something like:
Field _param1_ must be filled with numbers greater than _param2_
I have no clue how to do this.
Use GWT regular expressions:
//fields in your class
RegEx pattern1 = RegEx.compile("_param1_");
RegEx pattern2 = RegEx.compile("_param2_");
public String getString(String key, String replace1, String replace2){
// your original getString() method
String content = getString(key);
content = pattern1.replace(content,replace1);
content = pattern2.replace(content,replace2);
return content;
}
If your data contains Field _param1_ must be filled with numbers greater than _param2_ then this will replace _param1_ with content of string replace1.
I have a .NET Web Service(.asmx, not .svc) that accepts a string via HTTP POST. The strings it accepts are xml infosets I then parse via XElement.Parse. Once parsed into an XElement instance, I add a node to one of the elements within the instance.
The problem I'm having is that if a string representing an xml infoset comes through with then for some reason, me adding a node to the element XElement throws an exception such as "' ', hexadecimal value 0x06, is an invalid character. Line 1, position 40.". I get a wide array of 0x(*) errors thrown. If I don't attempt to add nodes to the XElement, everythings fine. Here's how I'm adding the element:
var prospect = doc.Element("prospect");
var provider = prospect.Element("provider");
provider.Add(new XElement("id",
new XAttribute("reservation-code",
reservationCode)
));
Is there some sort of string conversion I ought to be doing somewhere?
XML does not allow some Unicode characters. See the XML 1.0 Specification. Unfortunately, there is no standard way to escape those characters in XML, too. For example, you cannot escape it in valid XML using because of the Well-formedness constraint: Legal Character (see character references).
The XElement.ToString() has the check for those characters turned on. However, .NET does provide a way to turn character checking off. It is off by default in the System.Xml.XmlWriter instances. Therefore the following code will work:
/// <summary>
/// Returns the XML string of the <paramref name="xElement"/> WITHOUT CHARACTER CHECKING.
/// </summary>
/// <param name="xElement"></param>
/// <returns></returns>
public static string ToStringWithoutCharacterChecking(this XElement xElement)
{
using (System.IO.StringWriter stringWriter = new System.IO.StringWriter())
{
using (System.Xml.XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter))
{
xElement.WriteTo(xmlTextWriter);
}
return stringWriter.ToString();
}
}
Notice however that if you create an System.Xml.XmlWriter instance using System.Xml.XmlWriterSettings, the default is true for character checking. Therefore if you use System.Xml.XmlWriterSettings and want to turn off character checking, use:
XmlWriterSettings s = new XmlWriterSettings();
s.CheckCharacters = false;
using(XmlWriter w = XmlWriter.Create(..., s))
{
//etc.
}
thanks a lot, which solved my problem when I using linq to xsd.
here is my code:
//not using container.Save(new StreamWriter(toStream, new UTF8Encoding(false)));
instead using codes:
using (XmlWriter w = XmlWriter.Create(new StreamWriter(toStream, new UTF8Encoding(false)), new XmlWriterSettings
{//http://stackoverflow.com/questions/5709831/xelement-utf-8-issue
//http://stackoverflow.com/questions/10057171/xdocument-prevent-invalid-charachters
Indent = true,
CheckCharacters = false
}))
{
XTypedServices.Save(w, container.Untyped);
}
toStream.Flush();