function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JSandfortJSandfort 

Marshalling and Unmarshalling XML with Force WSC

Hi, I'm having some problems handling XML files with the Force WSC. First, an issue with unmarshalling CustomObject files:

com.sforce.ws.ConnectionException: UTF-8Not a valid enumeration for type: class com.sforce.soap.metadata.Encoding

 

I can see that the enumeration com.sforce.soap.metadata.Encoding is expecting "UTF_8" rather than "UTF-8", however the metadata is retrieved with the hyphen. Do I really have to find and replace this case before I can unmarshal the file properly? For the record, I used Force WSC to create these classes, Force WSC to retrieve the metadata, and I am using Force WSC to unmarshal the files. Is this framework incompatible with itself?

 

The issue with marshalling those CustomObject files is that I can't seem to save them in the same format that they were downloaded in. Whenever I marshall a metadata object to an XML file, it adds namespace prefixes ("n1:") to every tag, which is not how I want to store the data. So is there any way to marshal these files without the namespace prefixes, or will I have to do this myself after they are written?

 

Thanks in advance.

Pardeep GodaraPardeep Godara

Hi JSandfort,

 

Were you able to resolved this issue ? I having this simillar exception while loading metedata from an object XML.

 

thanks,

Pradeep

JSandfortJSandfort
The issue with the encoding enum hasn't been resolved, but it was sidestepped by modifying and re-compiling the parser in Force WSC.

I was wrong in the second issue (updated), it is possible to umarshal objects in this format with the WSC, but it's still less than ideal that it can't be written in the same format that it was loaded from.
Pardeep GodaraPardeep Godara

Can you do me a favour, please help me with the changes you made to the parser in Force WSC ?

 

thanks in advance!!

Kim GalantKim Galant
Just for the record: ran into the same problem just now, didn't have time for proper fix, but here's a hack that resolved it for me:

1. Download the WSC source from github: https://github.com/forcedotcom/wsc
2. Add the whole shebang to your project (in principle, it should be enough to just add com.sforce.ws.bind.TypeMapper, since that's where the hack is).
3. In line around 620, replace this:

if (type.isEnum()) {
            String value = readEnum(in, typeInfo, type);
            try {
                return Enum.valueOf(type, value);
            } catch (IllegalArgumentException e) {
                throw new ConnectionException(value + "Not a valid enumeration for type: " + type );
            }
        }

with this:

if (type.isEnum()) {
            String value = readEnum(in, typeInfo, type);
            try {
            	if (value.equals("UTF-8")) {
            		value = "UTF_8";
            	}
                return Enum.valueOf(type, value);
            } catch (IllegalArgumentException e) {
                throw new ConnectionException(value + "Not a valid enumeration for type: " + type );
            }
        }

This will make the eliminate the UTF_8 error....
SidharthSidharth
Hi, i am facing the same issue. Were you abel to figure out the solution. 
Error: com.sforce.ws.ConnectionException: UTF-8Not a valid enumeration for type: class com.sforce.soap.metadata.Encoding