Closed bonnysinha closed 9 years ago
You should not have the null pointer exception, but fields that do not correspond to features are allowed and would not throw exceptions.
Is there some kind of work around that I could approach. I am supposed to restrict files with incorrect attributes from going through.
Regards, Bonny.
There is nothing right now for that, some option could be added in a next release to throw exceptions for non valid json files.
Thank you Guillaume. Will look forward to it.
Hi Guillaume,
I am facing another issue. Whenever I try to load an xml with wrong contents say (IP_Addrs instead of IP_Addr or Databases instead of Database) I get an exception
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'Databases' not found. (file:///D:/SampleEMFProject/src/test/java/com/sample/emf/test/resources/wrong.xml, 2, 125) or org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'IP_Addrs' not found. (file:///D:/SampleEMFProject/src/test/java/com/sample/emf/test/resources/wrong.xml, 2, 125)
I tried loading a json instance with wrong information (Databases instead of Database) as shown below:
{ "eClass": "http://com.example.jndisample#//Server", "IP_Addr" : "SAMPLE_VALUE", "Port_Number" : 0, "Databases" : [ { "eClass": "http://com.example.jndisample#//Database", "Database_Name" : "SAMPLE_VALUE", "Username" : "SAMPLE_VALUE", "Password" : "SAMPLE_VALUE", "Schema" : { "eClass": "http://com.example.jndisample#//Schema", "Schema_Name" : "SAMPLE_VALUE", "Table" : [ { "eClass": "http://com.example.jndisample#//Table", "Table_Name" : "SAMPLE_VALUE", "Table_Number" : 0.0, "Has_Fk" : true, "List_Col" : "SAMPLE_VALUE" } ] } } ] }
A null pointer exception occurred instead of throwing an emf sort of exception as in the case of xml as shown above.
Next I gave another try with different incorrect values (IP_Addrs instead of IP_Addr).
{ "eClass": "http://com.example.jndisample#//Server", "IP_Addrs" : "SAMPLE_VALUE", "Port_Number" : 0, "Database" : [ { "eClass": "http://com.example.jndisample#//Database", "Database_Name" : "SAMPLE_VALUE", "Username" : "SAMPLE_VALUE", "Password" : "SAMPLE_VALUE", "Schema" : { "eClass": "http://com.example.jndisample#//Schema", "Schema_Name" : "SAMPLE_VALUE", "Table" : [ { "eClass": "http://com.example.jndisample#//Table", "Table_Name" : "SAMPLE_VALUE", "Table_Number" : 0.0, "Has_Fk" : true, "List_Col" : "SAMPLE_VALUE" } ] } } ] }
Here no exception was thrown and the json was loaded. But when I tried to read the value of the attribute, it returned null.
This is to ensure that the instance does not have any incorrect information. I would not want to load an incorrect json.
The ecore xmi as json and the code to retrieve instance value is the same as in #48
Am I missing out some additional information? Kindly advise.
Regards, Bonny.