'_$visited' property in Javascript object at the return of Obervable’s map() function

Asked

Viewed 41 times

0

I have a Webservice implemented with JAX-RS and I’m consuming it with a service(utilizando Angular 2)

Follow the service:

@Injectable()
export class ModeloService {

  constructor(private http: Http) {
  }

  getAll(): Observable<Modelo[]> {
    return this.http.get(myEnvironment.MODELO_SERVICE_PATH)
      .map(res => <Modelo[]> res.json());
  }

}

Modelo that’s my class:

export class Modelo{
  id: number;
  type: string;
  size: number;

  constructor() {

  }

}

It turns out that the function return map(), mounts the following object JavaScript, that is, it inserts this property _$visited : true:

{
  "id": 28,
  "type": "type",
  "size": null,
  "_$visited": true
}

That property "_$visited" is not part of my model there on the side of the Webservice, nor on the side of the front end, if I consume this Webservice by a Rest client (I use the Restlet Client), the returned json is the expected one or if I log the return of the res.json function itself():

{
  "id": 28,
  "type": "type",
  "size": null
}

I’d like to know first where this property comes from "_$visited" and what is the best way to get rid of it, because when I send this object to my web service again, it goes with this property.

  • In a quick Internet search, I saw that the place that uses this "_$visited" property is Primefaces, more specifically Primeng. You’re using this library?

  • Yes, I am using this library? can you pass me the reference?

  • I arrived at it through this site on Github https://github.com/primefaces/primeng/issues/1937 you probably don’t need to worry about this property, it’s just a Primeng control.

  • it happens that it is set and when I send a post with that same object pro web service, it gives error there on the other side.

  • I believe that any implementation you are using has some way of telling objects to ignore properties that are not mapped in your Backend. For example Jackson has @Jsonignoreproperties(ignoreUnknown = true), take a look.

  • I didn’t know this Annotation, vlw brother. it worked.

  • I have written an answer to help anyone else who has this problem. If you can accept it. Hug.

Show 2 more comments

1 answer

2


This property is added by Primeng to perform some library controls. Theoretically it should not influence the sending of requests to your backend.

But if the backend is releasing exceptions saying it doesn’t know the property, you can use an annotation from your JSON library to ignore these unknown properties.

An example of Jackson’s annotation in the communication class:

@JsonIgnoreProperties(ignoreUnknown = true)

This way the library will not attempt to parse this property.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.