# Using Jackson to parse JSON in an ingest processor

**URL:** <https://discuss.elastic.co/t/using-jackson-to-parse-json-in-an-ingest-processor/90927>\
**Category:** Elasticsearch\
**Created:** [June 27, 2017, 8:15am UTC](https://discuss.elastic.co/t/using-jackson-to-parse-json-in-an-ingest-processor/90927 "2017-06-27T08:15:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdesoyres](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pdesoyres/32/509_2.png) [@pdesoyres](https://discuss.elastic.co/u/pdesoyres)\
**Post date:** [June 27, 2017, 8:15am UTC](https://discuss.elastic.co/t/using-jackson-to-parse-json-in-an-ingest-processor/90927/1 "2017-06-27T08:15:15Z")

</div>

Hello,

I'm writing an ingest processor that has a JSON string as input. I'm using Jackson library to read that string but it seams that there are some limitation on the usage of the java reflection API. I'm getting the following error :

`com.fasterxml.jackson.databind.JsonMappingException: Can not access public com.lingway.xtirp.domain.RootLayerDTO() (from class com.lingway.xtirp.domain.RootLayerDTO; failed to set access: access denied ("java.lang.reflect.ReflectPermission" "suppressAccessChecks")`

As you can see the Reflection API tells me that the public empty constructor cannot be accessed due to the ReflectPermission restriction "suppressAccessChecks".

Does Elasticsearch sets those restriction ?  
Is there an alternative for JSON parsing in ingest processor ?

Any help would be apreciate. Thanks.

Pierre

I'm using elasticsearch 5.4.2

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [June 27, 2017, 10:24pm UTC](https://discuss.elastic.co/t/using-jackson-to-parse-json-in-an-ingest-processor/90927/2 "2017-06-27T22:24:20Z")

</div>

Scripts in elasticsearch run in a sandbox with limited privileges. In ES 5.x, you could try using groovy's builtin json parsing (I have not tried this, and it may result in more reflective failures, but it may be worth a try). That assumes you specify the script lang as groovy, which will be removed for 6.0. In 6.0, we are working on adding context specific (eg just for ingest scripts) whitelisting which would allow extra methods like this.

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [June 27, 2017, 10:25pm UTC](https://discuss.elastic.co/t/using-jackson-to-parse-json-in-an-ingest-processor/90927/3 "2017-06-27T22:25:30Z")

</div>

Another interim option is to write a native script plugin, where you could include any library/permissions you want. See [https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-engine.html](https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-engine.html).

---

<div class="post-metadata">

**Author:** ![pdesoyres](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pdesoyres/32/509_2.png) [@pdesoyres](https://discuss.elastic.co/u/pdesoyres)\
**Post date:** [June 28, 2017, 7:15am UTC](https://discuss.elastic.co/t/using-jackson-to-parse-json-in-an-ingest-processor/90927/4 "2017-06-28T07:15:41Z")

</div>

Thank you Ryan,

also I think I had to read [https://www.elastic.co/guide/en/elasticsearch/plugins/5.4/plugin-authors.html#plugin-authors-jsm](https://www.elastic.co/guide/en/elasticsearch/plugins/5.4/plugin-authors.html#plugin-authors-jsm)

---

<div class="post-metadata">

**Author:** ![pdesoyres](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pdesoyres/32/509_2.png) [@pdesoyres](https://discuss.elastic.co/u/pdesoyres)\
**Post date:** [June 28, 2017, 9:18am UTC](https://discuss.elastic.co/t/using-jackson-to-parse-json-in-an-ingest-processor/90927/5 "2017-06-28T09:18:34Z")

</div>

For those who are interested, I found the solution :

1- place a `plugin-security.policy` file alongside the plugin descriptor file :

```
grant {
    permission java.lang.RuntimePermission "accessDeclaredMembers";
    permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
};

```

2- Encapsulate the code using Jackson with java.security.AccessController.doPrivileged :

```
AccessController.doPrivileged((PrivilegedAction<RootLayerDTO>) () -> {
    ...
});
```

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [June 28, 2017, 9:39pm UTC](https://discuss.elastic.co/t/using-jackson-to-parse-json-in-an-ingest-processor/90927/6 "2017-06-28T21:39:09Z")

</div>

Are you using groovy or painless?

---

<div class="post-metadata">

**Author:** ![pdesoyres](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pdesoyres/32/509_2.png) [@pdesoyres](https://discuss.elastic.co/u/pdesoyres)\
**Post date:** [June 28, 2017, 10:15pm UTC](https://discuss.elastic.co/t/using-jackson-to-parse-json-in-an-ingest-processor/90927/7 "2017-06-28T22:15:11Z")

</div>

I am using Java to write my own ingest processor plugin

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 26, 2017, 10:15pm UTC](https://discuss.elastic.co/t/using-jackson-to-parse-json-in-an-ingest-processor/90927/8 "2017-07-26T22:15:21Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
