You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@syncope.apache.org by Juan Medina <so...@gmail.com> on 2018/12/02 09:52:16 UTC

Apache Syncope modify @XmlElement

favorit
<https://stackoverflow.com/questions/53558056/apache-syncope-modify-xmlelement/53562458?noredirect=1#>

I have a Java Backend responding rest request with response with this class:

package com.commonms.patientportal.tools;
import java.util.Collection;import java.util.Collections;
import javax.xml.bind.annotation.XmlElement;import
javax.xml.bind.annotation.XmlRootElement;
import org.codehaus.jackson.map.annotate.JsonSerialize;
@XmlRootElement@JsonSerialize(include =
JsonSerialize.Inclusion.NON_NULL)public class RestResponse<T> {
  @XmlElement(name = "METADATA")
  private JsonMetadata  jsonMetadata;
  private Collection<T> result;

  public RestResponse() {
    jsonMetadata = new JsonMetadata();
  }

  public RestResponse(JsonMetadata metadata) {
    this.jsonMetadata = metadata;
  }

  public JsonMetadata getJsonMetadata() {
    return jsonMetadata;
  }

  public void setJsonMetadata(JsonMetadata jsonMetadata) {
    this.jsonMetadata = jsonMetadata;
  }

  public Collection<T> getResult() {
    return result;
  }

  public void setResult(Collection<T> result) {
    this.result = result;
  }

  public void setObjectList(Collection<T> objectList) {
    if (objectList != null) {
      this.result = objectList;
    }
  }

  public void setObject(T object) {
    if (object != null) {
      setObjectList(Collections.singletonList(object));
    }
  }

  public void setErrorMessage(String msg) {
    jsonMetadata.setErrorMessage(msg);
  }

  public void setWarnMessage(String msg) {
    jsonMetadata.setWarnMessage(msg);
  }
}

And works ok sending something like this:

METADATA: {STATUS: "0", ERROR_MESSAGE: ""}
result: [{id: "4010", name: "Demo"}]

Now I'm trying to use Apache Syncope and want to use maven artifact like
read hear:

https://syncope.apache.org/docs/reference-guide.html#client-library

but when I add this lines:

<dependency>
  <groupId>org.apache.syncope.client</groupId>
  <artifactId>syncope-client-lib</artifactId>
  <version>2.1.2</version></dependency>

To the pom.xml in my proyect in Eclipse. Only add this lines, Do not do
anything else, and then the rest response changes to:

jsonMetadata: {status: "0", errorMessage: ""}
result: [{id: "4010", name: "Demo"}]

For me is a problem because I manage the errors whit this 'METADATA' word.

Does anyone know why this change occurs?




I ask this question in stackoverflow:


https://stackoverflow.com/questions/53558056/apache-syncope-modify-xmlelement/53562458

CORS with Standalone version

Posted by Juan Medina <so...@gmail.com>.
I'm starting with Apache Syncope for an application with Angular with a
back in Java.

I tried using the Java artifact but it gives me problems that I am not able
to solve and that I have asked in this list (
http://syncope-user.1051894.n5.nabble.com/Apache-Syncope-modify-XmlElement-td5710101.html
)

Actually that since I can not do it that way, I thought maybe I could throw
directly against Syncope from the front with REST requests. Is that
possible?

My idea is to do something like this:

let url = 'http: // localhost: 9080 / users';
>     this.http.post (url, {params: {param: 'string'}}). subscribe (data => {
>       console.log (data);
>     });
>   }


but when he tries, he says:

Access to XMLHttpRequest at 'http: // localhost: 9080 / users' from origin'
> http: // localhost: 4200 'has been blocked by CORS policy: Response to
> preflight request does not pass access control check: No' Access-Control
> -Allow-Origin 'header is present on the requested resource.


Can it be done like this? If so, how can I avoid cors? (I already have a
plugin installed on an extension in Crhome but it still gives me that error)

Re: Apache Syncope modify @XmlElement

Posted by Juan Medina <so...@gmail.com>.
Ok, Thanks a lot Francesco. I understand it's dificult witout see all the
app.

Maybe you are right and is something in the local env, but I don't see
anything... Someone has an idea of why it can be or how I can debug it,
because I don't find the moment when the xml is made before being sent (and
see METADATA in one case and this jsonMetadata in other)

El lun., 3 dic. 2018 a las 14:04, Francesco Chicchiriccò (<
ilgrosso@apache.org>) escribió:

> Hi,
> with the RestResponse class as reported by you below, and with a
> JsonMetadata class as follows:
>
> public class JsonMetadata implements Serializable {
>
>     private static final long serialVersionUID = 7093892252335858682L;
>
>     private String warnMessage;
>
>     private String errorMessage;
>
>     public String getWarnMessage() {
>         return warnMessage;
>     }
>
>     public void setWarnMessage(String warnMessage) {
>         this.warnMessage = warnMessage;
>     }
>
>     public String getErrorMessage() {
>         return errorMessage;
>     }
>
>     public void setErrorMessage(String errorMessage) {
>         this.errorMessage = errorMessage;
>     }
> }
>
> the following code:
>
>         RestResponse<String> response = new RestResponse<>();
>         new ObjectMapper().writeValue(System.out, response);
>
> prints out:
>
> {"METADATA":{"warnMessage":null,"errorMessage":null}}
>
> as expected, in a Maven project having syncope-client-lib:2.1.2 as
> dependency.
>
> There must be something more in your local env, then.
> Regards.
>
> On 03/12/18 13:44, Juan Medina wrote:
>
> I'm sorry, but this is desesperated:
>
> My My RestResponse class now looks like this but stills don't works :-(
>
> package com.commonms.patientportal.tools;
>
> import java.util.Collection;
> import java.util.Collections;
>
> import javax.xml.bind.annotation.XmlRootElement;
>
> import org.codehaus.jackson.map.annotate.JsonSerialize;
> import org.codehaus.jackson.annotate.JsonProperty;
>
> @XmlRootElement
> @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
> public class RestResponse<T> {
>   @JsonProperty("METADATA")
>   private JsonMetadata  jsonMetadata;
>   private Collection<T> result;
>
>   public RestResponse() {
>     jsonMetadata = new JsonMetadata();
>   }
>
>   public RestResponse(JsonMetadata metadata) {
>     this.jsonMetadata = metadata;
>   }
>
>   public JsonMetadata getJsonMetadata() {
>     return jsonMetadata;
>   }
>
>   public void setJsonMetadata(JsonMetadata jsonMetadata) {
>     this.jsonMetadata = jsonMetadata;
>   }
>
>   public Collection<T> getResult() {
>     return result;
>   }
>
>   public void setResult(Collection<T> result) {
>     this.result = result;
>   }
>
>   public void setObjectList(Collection<T> objectList) {
>     if (objectList != null) {
>       this.result = objectList;
>     }
>   }
>
>   public void setObject(T object) {
>     if (object != null) {
>       setObjectList(Collections.singletonList(object));
>     }
>   }
>
>   public void setErrorMessage(String msg) {
>     jsonMetadata.setErrorMessage(msg);
>   }
>
>   public void setWarnMessage(String msg) {
>     jsonMetadata.setWarnMessage(msg);
>   }
>
> }
>
>
> El lun., 3 dic. 2018 a las 12:40, Francesco Chicchiriccò (<
> ilgrosso@apache.org>) escribió:
>
>> On 03/12/18 12:31, Juan Medina wrote:
>>
>> Thanks a lot Francesco, but still don't works.
>>
>> You might try to remove both @JsonProperty and @JsonSetter I earlier
>> suggested, and replace
>>
>> @XmlElement(name = "METADATA")
>>
>> with
>>
>> @JsonProperty("METADATA")
>>
>> Regards.
>>
>> My RestResponse class now looks like this:
>>
>> package com.commonms.patientportal.tools;
>>
>> import java.util.Collection;
>> import java.util.Collections;
>>
>> import javax.xml.bind.annotation.XmlElement;
>> import javax.xml.bind.annotation.XmlRootElement;
>>
>> import org.codehaus.jackson.map.annotate.JsonSerialize;
>> import org.codehaus.jackson.annotate.JsonProperty;
>> import org.codehaus.jackson.annotate.JsonSetter;
>>
>> @XmlRootElement
>> @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
>> public class RestResponse<T> {
>>   @XmlElement(name = "METADATA")
>>   private JsonMetadata  jsonMetadata;
>>   private Collection<T> result;
>>
>>   public RestResponse() {
>>     jsonMetadata = new JsonMetadata();
>>   }
>>
>>   public RestResponse(JsonMetadata metadata) {
>>     this.jsonMetadata = metadata;
>>   }
>>
>>   @JsonProperty("METADATA")
>>   public JsonMetadata getJsonMetadata() {
>>     return jsonMetadata;
>>   }
>>
>>   @JsonSetter("schema")
>>   public void setJsonMetadata(JsonMetadata jsonMetadata) {
>>     this.jsonMetadata = jsonMetadata;
>>   }
>>
>>   public Collection<T> getResult() {
>>     return result;
>>   }
>>
>>   public void setResult(Collection<T> result) {
>>     this.result = result;
>>   }
>>
>>   public void setObjectList(Collection<T> objectList) {
>>     if (objectList != null) {
>>       this.result = objectList;
>>     }
>>   }
>>
>>   public void setObject(T object) {
>>     if (object != null) {
>>       setObjectList(Collections.singletonList(object));
>>     }
>>   }
>>
>>   public void setErrorMessage(String msg) {
>>     jsonMetadata.setErrorMessage(msg);
>>   }
>>
>>   public void setWarnMessage(String msg) {
>>     jsonMetadata.setWarnMessage(msg);
>>   }
>>
>>
>> But I still recibe from the back the object like this:
>>
>>
>> jsonMetadata: {status: "0", errorMessage: ""} result: [{id: "4010", name: "Demo"}]
>>
>> :-(
>>
>> El lun., 3 dic. 2018 a las 8:27, Francesco Chicchiriccò (<
>> ilgrosso@apache.org>) escribió:
>>
>>> On 03/12/18 08:20, Francesco Chicchiriccò wrote:
>>>
>>> Hi Juan,
>>> see my reply embedded below.
>>>
>>> Regards.
>>>
>>> On 02/12/18 10:52, Juan Medina wrote:
>>>
>>>
>>> I have a Java Backend responding rest request with response with this
>>> class:
>>>
>>> package com.commonms.patientportal.tools;
>>> import java.util.Collection;import java.util.Collections;
>>> import javax.xml.bind.annotation.XmlElement;import javax.xml.bind.annotation.XmlRootElement;
>>> import org.codehaus.jackson.map.annotate.JsonSerialize;
>>> @XmlRootElement@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)public class RestResponse<T> {
>>>   @XmlElement(name = "METADATA")
>>>   private JsonMetadata  jsonMetadata;
>>>   private Collection<T> result;
>>>
>>>   public RestResponse() {
>>>     jsonMetadata = new JsonMetadata();
>>>   }
>>>
>>>   public RestResponse(JsonMetadata metadata) {
>>>     this.jsonMetadata = metadata;
>>>   }
>>>
>>>   public JsonMetadata getJsonMetadata() {
>>>     return jsonMetadata;
>>>   }
>>>
>>>   public void setJsonMetadata(JsonMetadata jsonMetadata) {
>>>     this.jsonMetadata = jsonMetadata;
>>>   }
>>>
>>>   public Collection<T> getResult() {
>>>     return result;
>>>   }
>>>
>>>   public void setResult(Collection<T> result) {
>>>     this.result = result;
>>>   }
>>>
>>>   public void setObjectList(Collection<T> objectList) {
>>>     if (objectList != null) {
>>>       this.result = objectList;
>>>     }
>>>   }
>>>
>>>   public void setObject(T object) {
>>>     if (object != null) {
>>>       setObjectList(Collections.singletonList(object));
>>>     }
>>>   }
>>>
>>>   public void setErrorMessage(String msg) {
>>>     jsonMetadata.setErrorMessage(msg);
>>>   }
>>>
>>>   public void setWarnMessage(String msg) {
>>>     jsonMetadata.setWarnMessage(msg);
>>>   }
>>> }
>>>
>>> And works ok sending something like this:
>>>
>>> METADATA: {STATUS: "0", ERROR_MESSAGE: ""}
>>> result: [{id: "4010", name: "Demo"}]
>>>
>>> Now I'm trying to use Apache Syncope and want to use maven artifact like
>>> read hear:
>>>
>>> https://syncope.apache.org/docs/reference-guide.html#client-library
>>>
>>> but when I add this lines:
>>>
>>> <dependency>
>>>   <groupId>org.apache.syncope.client</groupId>
>>>   <artifactId>syncope-client-lib</artifactId>
>>>   <version>2.1.2</version></dependency>
>>>
>>> To the pom.xml in my proyect in Eclipse. Only add this lines, Do not do
>>> anything else, and then the rest response changes to:
>>>
>>> jsonMetadata: {status: "0", errorMessage: ""}
>>> result: [{id: "4010", name: "Demo"}]
>>>
>>> For me is a problem because I manage the errors whit this 'METADATA'
>>> word.
>>>
>>> Does anyone know why this change occurs?
>>>
>>> Hi,
>>> once you add the Syncope Client dependency as above, its configuration
>>> and transient dependencies (including syncope-common-lib, which deals with
>>> XML / JSON / YAML payloads) are pulled in too, which make Jackson to give
>>> less precedence to the field annotation
>>>
>>> @XmlElement(name = "METADATA")
>>>
>>> Long story short: it should be enough to add the @JsonProperty /
>>> @JsonSetter annotations as follows:
>>>
>>>   @JsonProperty("METADATA")
>>>   public JsonMetadata getJsonMetadata() {
>>>     return jsonMetadata;
>>>   }
>>>
>>>   @JsonSetter("schema")
>>>
>>> Sorry: this should be
>>>
>>> @JsonSetter("METADATA")
>>>
>>> of course...
>>>
>>>   public void setJsonMetadata(JsonMetadata jsonMetadata) {
>>>     this.jsonMetadata = jsonMetadata;
>>>   }
>>>
>>> I ask this question in stackoverflow:
>>>
>>>
>>> https://stackoverflow.com/questions/53558056/apache-syncope-modify-xmlelement/53562458
>>>
>>> --
> Francesco Chicchiriccò
>
> Tirasa - Open Source Excellencehttp://www.tirasa.net/
>
> Member at The Apache Software Foundation
> Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMailhttp://home.apache.org/~ilgrosso/
>
>

Re: Apache Syncope modify @XmlElement

Posted by Francesco Chicchiriccò <il...@apache.org>.
Hi,
with the RestResponse class as reported by you below, and with a 
JsonMetadata class as follows:

public class JsonMetadata implements Serializable {

     private static final long serialVersionUID = 7093892252335858682L;

     private String warnMessage;

     private String errorMessage;

     public String getWarnMessage() {
         return warnMessage;
     }

     public void setWarnMessage(String warnMessage) {
         this.warnMessage = warnMessage;
     }

     public String getErrorMessage() {
         return errorMessage;
     }

     public void setErrorMessage(String errorMessage) {
         this.errorMessage = errorMessage;
     }
}

the following code:

         RestResponse<String> response = new RestResponse<>();
         new ObjectMapper().writeValue(System.out, response);

prints out:

{"METADATA":{"warnMessage":null,"errorMessage":null}}

as expected, in a Maven project having syncope-client-lib:2.1.2 as 
dependency.

There must be something more in your local env, then.
Regards.

On 03/12/18 13:44, Juan Medina wrote:
> I'm sorry, but this is desesperated:
>
> My My RestResponse class now looks like this but stills don't works :-(
>>> package com.commonms.patientportal.tools; import 
>>> java.util.Collection; import java.util.Collections; import 
>>> javax.xml.bind.annotation.XmlRootElement; import 
>>> org.codehaus.jackson.map.annotate.JsonSerialize; import 
>>> org.codehaus.jackson.annotate.JsonProperty; @XmlRootElement 
>>> @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) public 
>>> class RestResponse<T> { @JsonProperty("METADATA") private 
>>> JsonMetadata jsonMetadata; private Collection<T> result; public 
>>> RestResponse() { jsonMetadata = new JsonMetadata(); } public 
>>> RestResponse(JsonMetadata metadata) { this.jsonMetadata = metadata; 
>>> } public JsonMetadata getJsonMetadata() { return jsonMetadata; } 
>>> public void setJsonMetadata(JsonMetadata jsonMetadata) { 
>>> this.jsonMetadata = jsonMetadata; } public Collection<T> getResult() 
>>> { return result; } public void setResult(Collection<T> result) { 
>>> this.result = result; } public void setObjectList(Collection<T> 
>>> objectList) { if (objectList != null) { this.result = objectList; } 
>>> } public void setObject(T object) { if (object != null) { 
>>> setObjectList(Collections.singletonList(object)); } } public void 
>>> setErrorMessage(String msg) { jsonMetadata.setErrorMessage(msg); } 
>>> public void setWarnMessage(String msg) { 
>>> jsonMetadata.setWarnMessage(msg); } }
>
> El lun., 3 dic. 2018 a las 12:40, Francesco Chicchiriccò 
> (<ilgrosso@apache.org <ma...@apache.org>>) escribió:
>
>     On 03/12/18 12:31, Juan Medina wrote:
>>     Thanks a lot Francesco, but still don't works.
>
>     You might try to remove both @JsonProperty and @JsonSetter I
>     earlier suggested, and replace
>
>     @XmlElement(name = "METADATA")
>
>     with
>
>     @JsonProperty("METADATA")
>
>     Regards.
>
>>     My RestResponse class now looks like this:
>>
>>>     package com.commonms.patientportal.tools; import
>>>     java.util.Collection; import java.util.Collections; import
>>>     javax.xml.bind.annotation.XmlElement; import
>>>     javax.xml.bind.annotation.XmlRootElement; import
>>>     org.codehaus.jackson.map.annotate.JsonSerialize; import
>>>     org.codehaus.jackson.annotate.JsonProperty; import
>>>     org.codehaus.jackson.annotate.JsonSetter; @XmlRootElement
>>>     @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
>>>     public class RestResponse<T> { @XmlElement(name = "METADATA")
>>>     private JsonMetadata jsonMetadata; private Collection<T> result;
>>>     public RestResponse() { jsonMetadata = new JsonMetadata(); }
>>>     public RestResponse(JsonMetadata metadata) { this.jsonMetadata =
>>>     metadata; } @JsonProperty("METADATA") public JsonMetadata
>>>     getJsonMetadata() { return jsonMetadata; } @JsonSetter("schema")
>>>     public void setJsonMetadata(JsonMetadata jsonMetadata) {
>>>     this.jsonMetadata = jsonMetadata; } public Collection<T>
>>>     getResult() { return result; } public void
>>>     setResult(Collection<T> result) { this.result = result; } public
>>>     void setObjectList(Collection<T> objectList) { if (objectList !=
>>>     null) { this.result = objectList; } } public void setObject(T
>>>     object) { if (object != null) {
>>>     setObjectList(Collections.singletonList(object)); } } public
>>>     void setErrorMessage(String msg) {
>>>     jsonMetadata.setErrorMessage(msg); } public void
>>>     setWarnMessage(String msg) { jsonMetadata.setWarnMessage(msg); }
>>     But I still recibe from the back the object like this:
>>
>>>     |jsonMetadata:{status:"0",errorMessage:""}|result:[{id:"4010",name:"Demo"}]
>>     :-(
>>
>>     El lun., 3 dic. 2018 a las 8:27, Francesco Chicchiriccò
>>     (<ilgrosso@apache.org <ma...@apache.org>>) escribió:
>>
>>         On 03/12/18 08:20, Francesco Chicchiriccò wrote:
>>>         Hi Juan,
>>>         see my reply embedded below.
>>>
>>>         Regards.
>>>
>>>         On 02/12/18 10:52, Juan Medina wrote:
>>>>
>>>>         I have a Java Backend responding rest request with response
>>>>         with this class:
>>>>
>>>>         |packagecom.commonms.patientportal.tools;importjava.util.Collection;importjava.util.Collections;importjavax.xml.bind.annotation.XmlElement;importjavax.xml.bind.annotation.XmlRootElement;importorg.codehaus.jackson.map.annotate.JsonSerialize;@XmlRootElement@JsonSerialize(include
>>>>         =JsonSerialize.Inclusion.NON_NULL)publicclassRestResponse<T>{@XmlElement(name
>>>>         ="METADATA")privateJsonMetadatajsonMetadata;privateCollection<T>result;publicRestResponse(){jsonMetadata
>>>>         =newJsonMetadata();}publicRestResponse(JsonMetadatametadata){this.jsonMetadata
>>>>         =metadata;}publicJsonMetadatagetJsonMetadata(){returnjsonMetadata;}publicvoidsetJsonMetadata(JsonMetadatajsonMetadata){this.jsonMetadata
>>>>         =jsonMetadata;}publicCollection<T>getResult(){returnresult;}publicvoidsetResult(Collection<T>result){this.result
>>>>         =result;}publicvoidsetObjectList(Collection<T>objectList){if(objectList
>>>>         !=null){this.result =objectList;}}publicvoidsetObject(T
>>>>         object){if(object!=null){setObjectList(Collections.singletonList(object));}}publicvoidsetErrorMessage(Stringmsg){jsonMetadata.setErrorMessage(msg);}publicvoidsetWarnMessage(Stringmsg){jsonMetadata.setWarnMessage(msg);}}|
>>>>
>>>>         And works ok sending something like this:
>>>>
>>>>         |METADATA:{STATUS:"0",ERROR_MESSAGE:""}result:[{id:"4010",name:"Demo"}]|
>>>>
>>>>         Now I'm trying to use Apache Syncope and want to use maven
>>>>         artifact like read hear:
>>>>
>>>>         https://syncope.apache.org/docs/reference-guide.html#client-library
>>>>
>>>>         but when I add this lines:
>>>>
>>>>         |<dependency><groupId>org.apache.syncope.client</groupId><artifactId>syncope-client-lib</artifactId><version>2.1.2</version></dependency>|
>>>>
>>>>         To the pom.xml in my proyect in Eclipse. Only add this
>>>>         lines, Do not do anything else, and then the rest response
>>>>         changes to:
>>>>
>>>>         |jsonMetadata:{status:"0",errorMessage:""}result:[{id:"4010",name:"Demo"}]|
>>>>
>>>>         For me is a problem because I manage the errors whit this
>>>>         'METADATA' word.
>>>>
>>>>         Does anyone know why this change occurs?
>>>>
>>>         Hi,
>>>         once you add the Syncope Client dependency as above, its
>>>         configuration and transient dependencies (including
>>>         syncope-common-lib, which deals with XML / JSON / YAML
>>>         payloads) are pulled in too, which make Jackson to give less
>>>         precedence to the field annotation
>>>
>>>         @XmlElement(name = "METADATA")
>>>
>>>         Long story short: it should be enough to add the
>>>         @JsonProperty / @JsonSetter annotations as follows:
>>>
>>>           @JsonProperty("METADATA")
>>>           public JsonMetadata getJsonMetadata() {
>>>             return jsonMetadata;
>>>           }
>>>
>>>           @JsonSetter("schema")
>>>
>>         Sorry: this should be
>>
>>         @JsonSetter("METADATA")
>>
>>         of course...
>>
>>>           public void setJsonMetadata(JsonMetadata jsonMetadata) {
>>>             this.jsonMetadata = jsonMetadata;
>>>           }
>>>
>>>>         I ask this question in stackoverflow:
>>>>
>>>>         https://stackoverflow.com/questions/53558056/apache-syncope-modify-xmlelement/53562458
>>>>
-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Member at The Apache Software Foundation
Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMail
http://home.apache.org/~ilgrosso/


Re: Apache Syncope modify @XmlElement

Posted by Juan Medina <so...@gmail.com>.
I'm sorry, but this is desesperated:

My My RestResponse class now looks like this but stills don't works :-(

package com.commonms.patientportal.tools;

import java.util.Collection;
import java.util.Collections;

import javax.xml.bind.annotation.XmlRootElement;

import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.annotate.JsonProperty;

@XmlRootElement
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class RestResponse<T> {
  @JsonProperty("METADATA")
  private JsonMetadata  jsonMetadata;
  private Collection<T> result;

  public RestResponse() {
    jsonMetadata = new JsonMetadata();
  }

  public RestResponse(JsonMetadata metadata) {
    this.jsonMetadata = metadata;
  }

  public JsonMetadata getJsonMetadata() {
    return jsonMetadata;
  }

  public void setJsonMetadata(JsonMetadata jsonMetadata) {
    this.jsonMetadata = jsonMetadata;
  }

  public Collection<T> getResult() {
    return result;
  }

  public void setResult(Collection<T> result) {
    this.result = result;
  }

  public void setObjectList(Collection<T> objectList) {
    if (objectList != null) {
      this.result = objectList;
    }
  }

  public void setObject(T object) {
    if (object != null) {
      setObjectList(Collections.singletonList(object));
    }
  }

  public void setErrorMessage(String msg) {
    jsonMetadata.setErrorMessage(msg);
  }

  public void setWarnMessage(String msg) {
    jsonMetadata.setWarnMessage(msg);
  }

}


El lun., 3 dic. 2018 a las 12:40, Francesco Chicchiriccò (<
ilgrosso@apache.org>) escribió:

> On 03/12/18 12:31, Juan Medina wrote:
>
> Thanks a lot Francesco, but still don't works.
>
> You might try to remove both @JsonProperty and @JsonSetter I earlier
> suggested, and replace
>
> @XmlElement(name = "METADATA")
>
> with
>
> @JsonProperty("METADATA")
>
> Regards.
>
> My RestResponse class now looks like this:
>
> package com.commonms.patientportal.tools;
>
> import java.util.Collection;
> import java.util.Collections;
>
> import javax.xml.bind.annotation.XmlElement;
> import javax.xml.bind.annotation.XmlRootElement;
>
> import org.codehaus.jackson.map.annotate.JsonSerialize;
> import org.codehaus.jackson.annotate.JsonProperty;
> import org.codehaus.jackson.annotate.JsonSetter;
>
> @XmlRootElement
> @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
> public class RestResponse<T> {
>   @XmlElement(name = "METADATA")
>   private JsonMetadata  jsonMetadata;
>   private Collection<T> result;
>
>   public RestResponse() {
>     jsonMetadata = new JsonMetadata();
>   }
>
>   public RestResponse(JsonMetadata metadata) {
>     this.jsonMetadata = metadata;
>   }
>
>   @JsonProperty("METADATA")
>   public JsonMetadata getJsonMetadata() {
>     return jsonMetadata;
>   }
>
>   @JsonSetter("schema")
>   public void setJsonMetadata(JsonMetadata jsonMetadata) {
>     this.jsonMetadata = jsonMetadata;
>   }
>
>   public Collection<T> getResult() {
>     return result;
>   }
>
>   public void setResult(Collection<T> result) {
>     this.result = result;
>   }
>
>   public void setObjectList(Collection<T> objectList) {
>     if (objectList != null) {
>       this.result = objectList;
>     }
>   }
>
>   public void setObject(T object) {
>     if (object != null) {
>       setObjectList(Collections.singletonList(object));
>     }
>   }
>
>   public void setErrorMessage(String msg) {
>     jsonMetadata.setErrorMessage(msg);
>   }
>
>   public void setWarnMessage(String msg) {
>     jsonMetadata.setWarnMessage(msg);
>   }
>
>
> But I still recibe from the back the object like this:
>
>
> jsonMetadata: {status: "0", errorMessage: ""} result: [{id: "4010", name: "Demo"}]
>
> :-(
>
> El lun., 3 dic. 2018 a las 8:27, Francesco Chicchiriccò (<
> ilgrosso@apache.org>) escribió:
>
>> On 03/12/18 08:20, Francesco Chicchiriccò wrote:
>>
>> Hi Juan,
>> see my reply embedded below.
>>
>> Regards.
>>
>> On 02/12/18 10:52, Juan Medina wrote:
>>
>>
>> I have a Java Backend responding rest request with response with this
>> class:
>>
>> package com.commonms.patientportal.tools;
>> import java.util.Collection;import java.util.Collections;
>> import javax.xml.bind.annotation.XmlElement;import javax.xml.bind.annotation.XmlRootElement;
>> import org.codehaus.jackson.map.annotate.JsonSerialize;
>> @XmlRootElement@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)public class RestResponse<T> {
>>   @XmlElement(name = "METADATA")
>>   private JsonMetadata  jsonMetadata;
>>   private Collection<T> result;
>>
>>   public RestResponse() {
>>     jsonMetadata = new JsonMetadata();
>>   }
>>
>>   public RestResponse(JsonMetadata metadata) {
>>     this.jsonMetadata = metadata;
>>   }
>>
>>   public JsonMetadata getJsonMetadata() {
>>     return jsonMetadata;
>>   }
>>
>>   public void setJsonMetadata(JsonMetadata jsonMetadata) {
>>     this.jsonMetadata = jsonMetadata;
>>   }
>>
>>   public Collection<T> getResult() {
>>     return result;
>>   }
>>
>>   public void setResult(Collection<T> result) {
>>     this.result = result;
>>   }
>>
>>   public void setObjectList(Collection<T> objectList) {
>>     if (objectList != null) {
>>       this.result = objectList;
>>     }
>>   }
>>
>>   public void setObject(T object) {
>>     if (object != null) {
>>       setObjectList(Collections.singletonList(object));
>>     }
>>   }
>>
>>   public void setErrorMessage(String msg) {
>>     jsonMetadata.setErrorMessage(msg);
>>   }
>>
>>   public void setWarnMessage(String msg) {
>>     jsonMetadata.setWarnMessage(msg);
>>   }
>> }
>>
>> And works ok sending something like this:
>>
>> METADATA: {STATUS: "0", ERROR_MESSAGE: ""}
>> result: [{id: "4010", name: "Demo"}]
>>
>> Now I'm trying to use Apache Syncope and want to use maven artifact like
>> read hear:
>>
>> https://syncope.apache.org/docs/reference-guide.html#client-library
>>
>> but when I add this lines:
>>
>> <dependency>
>>   <groupId>org.apache.syncope.client</groupId>
>>   <artifactId>syncope-client-lib</artifactId>
>>   <version>2.1.2</version></dependency>
>>
>> To the pom.xml in my proyect in Eclipse. Only add this lines, Do not do
>> anything else, and then the rest response changes to:
>>
>> jsonMetadata: {status: "0", errorMessage: ""}
>> result: [{id: "4010", name: "Demo"}]
>>
>> For me is a problem because I manage the errors whit this 'METADATA' word.
>>
>> Does anyone know why this change occurs?
>>
>> Hi,
>> once you add the Syncope Client dependency as above, its configuration
>> and transient dependencies (including syncope-common-lib, which deals with
>> XML / JSON / YAML payloads) are pulled in too, which make Jackson to give
>> less precedence to the field annotation
>>
>> @XmlElement(name = "METADATA")
>>
>> Long story short: it should be enough to add the @JsonProperty /
>> @JsonSetter annotations as follows:
>>
>>   @JsonProperty("METADATA")
>>   public JsonMetadata getJsonMetadata() {
>>     return jsonMetadata;
>>   }
>>
>>   @JsonSetter("schema")
>>
>> Sorry: this should be
>>
>> @JsonSetter("METADATA")
>>
>> of course...
>>
>>   public void setJsonMetadata(JsonMetadata jsonMetadata) {
>>     this.jsonMetadata = jsonMetadata;
>>   }
>>
>> I ask this question in stackoverflow:
>>
>>
>> https://stackoverflow.com/questions/53558056/apache-syncope-modify-xmlelement/53562458
>>
>> --
> Francesco Chicchiriccò
>
> Tirasa - Open Source Excellencehttp://www.tirasa.net/
>
> Member at The Apache Software Foundation
> Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMailhttp://home.apache.org/~ilgrosso/
>
>

Re: Apache Syncope modify @XmlElement

Posted by Francesco Chicchiriccò <il...@apache.org>.
On 03/12/18 12:31, Juan Medina wrote:
> Thanks a lot Francesco, but still don't works.

You might try to remove both @JsonProperty and @JsonSetter I earlier 
suggested, and replace

@XmlElement(name = "METADATA")

with

@JsonProperty("METADATA")

Regards.

> My RestResponse class now looks like this:
>
>> package com.commonms.patientportal.tools; import 
>> java.util.Collection; import java.util.Collections; import 
>> javax.xml.bind.annotation.XmlElement; import 
>> javax.xml.bind.annotation.XmlRootElement; import 
>> org.codehaus.jackson.map.annotate.JsonSerialize; import 
>> org.codehaus.jackson.annotate.JsonProperty; import 
>> org.codehaus.jackson.annotate.JsonSetter; @XmlRootElement 
>> @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) public 
>> class RestResponse<T> { @XmlElement(name = "METADATA") private 
>> JsonMetadata jsonMetadata; private Collection<T> result; public 
>> RestResponse() { jsonMetadata = new JsonMetadata(); } public 
>> RestResponse(JsonMetadata metadata) { this.jsonMetadata = metadata; } 
>> @JsonProperty("METADATA") public JsonMetadata getJsonMetadata() { 
>> return jsonMetadata; } @JsonSetter("schema") public void 
>> setJsonMetadata(JsonMetadata jsonMetadata) { this.jsonMetadata = 
>> jsonMetadata; } public Collection<T> getResult() { return result; } 
>> public void setResult(Collection<T> result) { this.result = result; } 
>> public void setObjectList(Collection<T> objectList) { if (objectList 
>> != null) { this.result = objectList; } } public void setObject(T 
>> object) { if (object != null) { 
>> setObjectList(Collections.singletonList(object)); } } public void 
>> setErrorMessage(String msg) { jsonMetadata.setErrorMessage(msg); } 
>> public void setWarnMessage(String msg) { 
>> jsonMetadata.setWarnMessage(msg); }
> But I still recibe from the back the object like this:
>
>> |jsonMetadata:{status:"0",errorMessage:""}|result:[{id:"4010",name:"Demo"}]
> :-(
>
> El lun., 3 dic. 2018 a las 8:27, Francesco Chicchiriccò 
> (<ilgrosso@apache.org <ma...@apache.org>>) escribió:
>
>     On 03/12/18 08:20, Francesco Chicchiriccò wrote:
>>     Hi Juan,
>>     see my reply embedded below.
>>
>>     Regards.
>>
>>     On 02/12/18 10:52, Juan Medina wrote:
>>>
>>>     I have a Java Backend responding rest request with response with
>>>     this class:
>>>
>>>     |packagecom.commonms.patientportal.tools;importjava.util.Collection;importjava.util.Collections;importjavax.xml.bind.annotation.XmlElement;importjavax.xml.bind.annotation.XmlRootElement;importorg.codehaus.jackson.map.annotate.JsonSerialize;@XmlRootElement@JsonSerialize(include
>>>     =JsonSerialize.Inclusion.NON_NULL)publicclassRestResponse<T>{@XmlElement(name
>>>     ="METADATA")privateJsonMetadatajsonMetadata;privateCollection<T>result;publicRestResponse(){jsonMetadata
>>>     =newJsonMetadata();}publicRestResponse(JsonMetadatametadata){this.jsonMetadata
>>>     =metadata;}publicJsonMetadatagetJsonMetadata(){returnjsonMetadata;}publicvoidsetJsonMetadata(JsonMetadatajsonMetadata){this.jsonMetadata
>>>     =jsonMetadata;}publicCollection<T>getResult(){returnresult;}publicvoidsetResult(Collection<T>result){this.result
>>>     =result;}publicvoidsetObjectList(Collection<T>objectList){if(objectList
>>>     !=null){this.result =objectList;}}publicvoidsetObject(T
>>>     object){if(object!=null){setObjectList(Collections.singletonList(object));}}publicvoidsetErrorMessage(Stringmsg){jsonMetadata.setErrorMessage(msg);}publicvoidsetWarnMessage(Stringmsg){jsonMetadata.setWarnMessage(msg);}}|
>>>
>>>     And works ok sending something like this:
>>>
>>>     |METADATA:{STATUS:"0",ERROR_MESSAGE:""}result:[{id:"4010",name:"Demo"}]|
>>>
>>>     Now I'm trying to use Apache Syncope and want to use maven
>>>     artifact like read hear:
>>>
>>>     https://syncope.apache.org/docs/reference-guide.html#client-library
>>>
>>>     but when I add this lines:
>>>
>>>     |<dependency><groupId>org.apache.syncope.client</groupId><artifactId>syncope-client-lib</artifactId><version>2.1.2</version></dependency>|
>>>
>>>     To the pom.xml in my proyect in Eclipse. Only add this lines, Do
>>>     not do anything else, and then the rest response changes to:
>>>
>>>     |jsonMetadata:{status:"0",errorMessage:""}result:[{id:"4010",name:"Demo"}]|
>>>
>>>     For me is a problem because I manage the errors whit this
>>>     'METADATA' word.
>>>
>>>     Does anyone know why this change occurs?
>>>
>>     Hi,
>>     once you add the Syncope Client dependency as above, its
>>     configuration and transient dependencies (including
>>     syncope-common-lib, which deals with XML / JSON / YAML payloads)
>>     are pulled in too, which make Jackson to give less precedence to
>>     the field annotation
>>
>>     @XmlElement(name = "METADATA")
>>
>>     Long story short: it should be enough to add the @JsonProperty /
>>     @JsonSetter annotations as follows:
>>
>>       @JsonProperty("METADATA")
>>       public JsonMetadata getJsonMetadata() {
>>         return jsonMetadata;
>>       }
>>
>>       @JsonSetter("schema")
>>
>     Sorry: this should be
>
>     @JsonSetter("METADATA")
>
>     of course...
>
>>       public void setJsonMetadata(JsonMetadata jsonMetadata) {
>>         this.jsonMetadata = jsonMetadata;
>>       }
>>
>>>     I ask this question in stackoverflow:
>>>
>>>     https://stackoverflow.com/questions/53558056/apache-syncope-modify-xmlelement/53562458
>>>
-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Member at The Apache Software Foundation
Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMail
http://home.apache.org/~ilgrosso/


Re: Apache Syncope modify @XmlElement

Posted by Juan Medina <so...@gmail.com>.
Thanks a lot Francesco, but still don't works.

My RestResponse class now looks like this:

package com.commonms.patientportal.tools;

import java.util.Collection;
import java.util.Collections;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.annotate.JsonSetter;

@XmlRootElement
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class RestResponse<T> {
  @XmlElement(name = "METADATA")
  private JsonMetadata  jsonMetadata;
  private Collection<T> result;

  public RestResponse() {
    jsonMetadata = new JsonMetadata();
  }

  public RestResponse(JsonMetadata metadata) {
    this.jsonMetadata = metadata;
  }

  @JsonProperty("METADATA")
  public JsonMetadata getJsonMetadata() {
    return jsonMetadata;
  }

  @JsonSetter("schema")
  public void setJsonMetadata(JsonMetadata jsonMetadata) {
    this.jsonMetadata = jsonMetadata;
  }

  public Collection<T> getResult() {
    return result;
  }

  public void setResult(Collection<T> result) {
    this.result = result;
  }

  public void setObjectList(Collection<T> objectList) {
    if (objectList != null) {
      this.result = objectList;
    }
  }

  public void setObject(T object) {
    if (object != null) {
      setObjectList(Collections.singletonList(object));
    }
  }

  public void setErrorMessage(String msg) {
    jsonMetadata.setErrorMessage(msg);
  }

  public void setWarnMessage(String msg) {
    jsonMetadata.setWarnMessage(msg);
  }


But I still recibe from the back the object like this:


jsonMetadata: {status: "0", errorMessage: ""} result: [{id: "4010",
name: "Demo"}]

:-(

El lun., 3 dic. 2018 a las 8:27, Francesco Chicchiriccò (<
ilgrosso@apache.org>) escribió:

> On 03/12/18 08:20, Francesco Chicchiriccò wrote:
>
> Hi Juan,
> see my reply embedded below.
>
> Regards.
>
> On 02/12/18 10:52, Juan Medina wrote:
>
>
> I have a Java Backend responding rest request with response with this
> class:
>
> package com.commonms.patientportal.tools;
> import java.util.Collection;import java.util.Collections;
> import javax.xml.bind.annotation.XmlElement;import javax.xml.bind.annotation.XmlRootElement;
> import org.codehaus.jackson.map.annotate.JsonSerialize;
> @XmlRootElement@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)public class RestResponse<T> {
>   @XmlElement(name = "METADATA")
>   private JsonMetadata  jsonMetadata;
>   private Collection<T> result;
>
>   public RestResponse() {
>     jsonMetadata = new JsonMetadata();
>   }
>
>   public RestResponse(JsonMetadata metadata) {
>     this.jsonMetadata = metadata;
>   }
>
>   public JsonMetadata getJsonMetadata() {
>     return jsonMetadata;
>   }
>
>   public void setJsonMetadata(JsonMetadata jsonMetadata) {
>     this.jsonMetadata = jsonMetadata;
>   }
>
>   public Collection<T> getResult() {
>     return result;
>   }
>
>   public void setResult(Collection<T> result) {
>     this.result = result;
>   }
>
>   public void setObjectList(Collection<T> objectList) {
>     if (objectList != null) {
>       this.result = objectList;
>     }
>   }
>
>   public void setObject(T object) {
>     if (object != null) {
>       setObjectList(Collections.singletonList(object));
>     }
>   }
>
>   public void setErrorMessage(String msg) {
>     jsonMetadata.setErrorMessage(msg);
>   }
>
>   public void setWarnMessage(String msg) {
>     jsonMetadata.setWarnMessage(msg);
>   }
> }
>
> And works ok sending something like this:
>
> METADATA: {STATUS: "0", ERROR_MESSAGE: ""}
> result: [{id: "4010", name: "Demo"}]
>
> Now I'm trying to use Apache Syncope and want to use maven artifact like
> read hear:
>
> https://syncope.apache.org/docs/reference-guide.html#client-library
>
> but when I add this lines:
>
> <dependency>
>   <groupId>org.apache.syncope.client</groupId>
>   <artifactId>syncope-client-lib</artifactId>
>   <version>2.1.2</version></dependency>
>
> To the pom.xml in my proyect in Eclipse. Only add this lines, Do not do
> anything else, and then the rest response changes to:
>
> jsonMetadata: {status: "0", errorMessage: ""}
> result: [{id: "4010", name: "Demo"}]
>
> For me is a problem because I manage the errors whit this 'METADATA' word.
>
> Does anyone know why this change occurs?
>
> Hi,
> once you add the Syncope Client dependency as above, its configuration and
> transient dependencies (including syncope-common-lib, which deals with XML
> / JSON / YAML payloads) are pulled in too, which make Jackson to give less
> precedence to the field annotation
>
> @XmlElement(name = "METADATA")
>
> Long story short: it should be enough to add the @JsonProperty /
> @JsonSetter annotations as follows:
>
>   @JsonProperty("METADATA")
>   public JsonMetadata getJsonMetadata() {
>     return jsonMetadata;
>   }
>
>   @JsonSetter("schema")
>
> Sorry: this should be
>
> @JsonSetter("METADATA")
>
> of course...
>
>   public void setJsonMetadata(JsonMetadata jsonMetadata) {
>     this.jsonMetadata = jsonMetadata;
>   }
>
> I ask this question in stackoverflow:
>
>
> https://stackoverflow.com/questions/53558056/apache-syncope-modify-xmlelement/53562458
>
> --
> Francesco Chicchiriccò
>
> Tirasa - Open Source Excellencehttp://www.tirasa.net/
>
> Member at The Apache Software Foundation
> Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMailhttp://home.apache.org/~ilgrosso/
>
>
> --
> Francesco Chicchiriccò
>
> Tirasa - Open Source Excellencehttp://www.tirasa.net/
>
> Member at The Apache Software Foundation
> Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMailhttp://home.apache.org/~ilgrosso/
>
>

Re: Apache Syncope modify @XmlElement

Posted by Francesco Chicchiriccò <il...@apache.org>.
On 03/12/18 08:20, Francesco Chicchiriccò wrote:
> Hi Juan,
> see my reply embedded below.
>
> Regards.
>
> On 02/12/18 10:52, Juan Medina wrote:
>>
>> I have a Java Backend responding rest request with response with this 
>> class:
>>
>> |packagecom.commonms.patientportal.tools;importjava.util.Collection;importjava.util.Collections;importjavax.xml.bind.annotation.XmlElement;importjavax.xml.bind.annotation.XmlRootElement;importorg.codehaus.jackson.map.annotate.JsonSerialize;@XmlRootElement@JsonSerialize(include 
>> =JsonSerialize.Inclusion.NON_NULL)publicclassRestResponse<T>{@XmlElement(name 
>> ="METADATA")privateJsonMetadatajsonMetadata;privateCollection<T>result;publicRestResponse(){jsonMetadata 
>> =newJsonMetadata();}publicRestResponse(JsonMetadatametadata){this.jsonMetadata 
>> =metadata;}publicJsonMetadatagetJsonMetadata(){returnjsonMetadata;}publicvoidsetJsonMetadata(JsonMetadatajsonMetadata){this.jsonMetadata 
>> =jsonMetadata;}publicCollection<T>getResult(){returnresult;}publicvoidsetResult(Collection<T>result){this.result 
>> =result;}publicvoidsetObjectList(Collection<T>objectList){if(objectList 
>> !=null){this.result =objectList;}}publicvoidsetObject(T 
>> object){if(object!=null){setObjectList(Collections.singletonList(object));}}publicvoidsetErrorMessage(Stringmsg){jsonMetadata.setErrorMessage(msg);}publicvoidsetWarnMessage(Stringmsg){jsonMetadata.setWarnMessage(msg);}}|
>>
>> And works ok sending something like this:
>>
>> |METADATA:{STATUS:"0",ERROR_MESSAGE:""}result:[{id:"4010",name:"Demo"}]|
>>
>> Now I'm trying to use Apache Syncope and want to use maven artifact 
>> like read hear:
>>
>> https://syncope.apache.org/docs/reference-guide.html#client-library
>>
>> but when I add this lines:
>>
>> |<dependency><groupId>org.apache.syncope.client</groupId><artifactId>syncope-client-lib</artifactId><version>2.1.2</version></dependency>|
>>
>> To the pom.xml in my proyect in Eclipse. Only add this lines, Do not 
>> do anything else, and then the rest response changes to:
>>
>> |jsonMetadata:{status:"0",errorMessage:""}result:[{id:"4010",name:"Demo"}]|
>>
>> For me is a problem because I manage the errors whit this 'METADATA' 
>> word.
>>
>> Does anyone know why this change occurs?
>>
> Hi,
> once you add the Syncope Client dependency as above, its configuration 
> and transient dependencies (including syncope-common-lib, which deals 
> with XML / JSON / YAML payloads) are pulled in too, which make Jackson 
> to give less precedence to the field annotation
>
> @XmlElement(name = "METADATA")
>
> Long story short: it should be enough to add the @JsonProperty / 
> @JsonSetter annotations as follows:
>
>   @JsonProperty("METADATA")
>   public JsonMetadata getJsonMetadata() {
>     return jsonMetadata;
>   }
>
>   @JsonSetter("schema")
>
Sorry: this should be

@JsonSetter("METADATA")

of course...

>   public void setJsonMetadata(JsonMetadata jsonMetadata) {
>     this.jsonMetadata = jsonMetadata;
>   }
>
>> I ask this question in stackoverflow:
>>
>> https://stackoverflow.com/questions/53558056/apache-syncope-modify-xmlelement/53562458
>>
> -- 
> Francesco Chicchiriccò
>
> Tirasa - Open Source Excellence
> http://www.tirasa.net/
>
> Member at The Apache Software Foundation
> Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMail
> http://home.apache.org/~ilgrosso/


-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Member at The Apache Software Foundation
Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMail
http://home.apache.org/~ilgrosso/


Re: Apache Syncope modify @XmlElement

Posted by Francesco Chicchiriccò <il...@apache.org>.
Hi Juan,
see my reply embedded below.

Regards.

On 02/12/18 10:52, Juan Medina wrote:
>
> I have a Java Backend responding rest request with response with this 
> class:
>
> |packagecom.commonms.patientportal.tools;importjava.util.Collection;importjava.util.Collections;importjavax.xml.bind.annotation.XmlElement;importjavax.xml.bind.annotation.XmlRootElement;importorg.codehaus.jackson.map.annotate.JsonSerialize;@XmlRootElement@JsonSerialize(include 
> =JsonSerialize.Inclusion.NON_NULL)publicclassRestResponse<T>{@XmlElement(name 
> ="METADATA")privateJsonMetadatajsonMetadata;privateCollection<T>result;publicRestResponse(){jsonMetadata 
> =newJsonMetadata();}publicRestResponse(JsonMetadatametadata){this.jsonMetadata 
> =metadata;}publicJsonMetadatagetJsonMetadata(){returnjsonMetadata;}publicvoidsetJsonMetadata(JsonMetadatajsonMetadata){this.jsonMetadata 
> =jsonMetadata;}publicCollection<T>getResult(){returnresult;}publicvoidsetResult(Collection<T>result){this.result 
> =result;}publicvoidsetObjectList(Collection<T>objectList){if(objectList 
> !=null){this.result =objectList;}}publicvoidsetObject(T 
> object){if(object!=null){setObjectList(Collections.singletonList(object));}}publicvoidsetErrorMessage(Stringmsg){jsonMetadata.setErrorMessage(msg);}publicvoidsetWarnMessage(Stringmsg){jsonMetadata.setWarnMessage(msg);}}|
>
> And works ok sending something like this:
>
> |METADATA:{STATUS:"0",ERROR_MESSAGE:""}result:[{id:"4010",name:"Demo"}]|
>
> Now I'm trying to use Apache Syncope and want to use maven artifact 
> like read hear:
>
> https://syncope.apache.org/docs/reference-guide.html#client-library
>
> but when I add this lines:
>
> |<dependency><groupId>org.apache.syncope.client</groupId><artifactId>syncope-client-lib</artifactId><version>2.1.2</version></dependency>|
>
> To the pom.xml in my proyect in Eclipse. Only add this lines, Do not 
> do anything else, and then the rest response changes to:
>
> |jsonMetadata:{status:"0",errorMessage:""}result:[{id:"4010",name:"Demo"}]|
>
> For me is a problem because I manage the errors whit this 'METADATA' word.
>
> Does anyone know why this change occurs?
>
Hi,
once you add the Syncope Client dependency as above, its configuration 
and transient dependencies (including syncope-common-lib, which deals 
with XML / JSON / YAML payloads) are pulled in too, which make Jackson 
to give less precedence to the field annotation

@XmlElement(name = "METADATA")

Long story short: it should be enough to add the @JsonProperty / 
@JsonSetter annotations as follows:

   @JsonProperty("METADATA")
   public JsonMetadata getJsonMetadata() {
     return jsonMetadata;
   }

   @JsonSetter("schema")
   public void setJsonMetadata(JsonMetadata jsonMetadata) {
     this.jsonMetadata = jsonMetadata;
   }

> I ask this question in stackoverflow:
>
> https://stackoverflow.com/questions/53558056/apache-syncope-modify-xmlelement/53562458
>
-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Member at The Apache Software Foundation
Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMail
http://home.apache.org/~ilgrosso/