You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@jmeter.apache.org by bu...@apache.org on 2016/05/21 03:45:24 UTC
[Bug 59609] New: JSONPathPostProcessor not evaluating correctly
https://bz.apache.org/bugzilla/show_bug.cgi?id=59609
Bug ID: 59609
Summary: JSONPathPostProcessor not evaluating correctly
Product: JMeter
Version: 3.0
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: HTTP
Assignee: issues@jmeter.apache.org
Reporter: michael.chirlin@gmail.com
The JSONPathPostProcessor uses the follow to turn the JSON results to string,
however if toJSONString isn't used then all of the quotes will be removed.
Current Example
With this Code (JSONPostProcessor 166-167):
Object obj = extractedValues.get(0);
String objAsString = obj != null ? obj.toString() : ""; //$NON-NLS-1$
Run with:
$.context
Against:
{
"context": {
"#v": "abc123",
"#t": "string"
}
}
Results in:
{#v: abc123, #t: string}
This is incorrect, all of the quotes have been removed.
It should be replaced with something more like:
String objAsString = "";
if (extractedValues instanceof JSONArray) {
objAsString = new JSONObject((Map) extractedValues.get(0)).toJSONString();
}
Which when tested results:
{"#t":"string","#v":"abc123"}
This obviously needs to be extended for examples where more than one response
is returned.
--
You are receiving this mail because:
You are the assignee for the bug.
[Bug 59609] JSONPathPostProcessor not evaluating correctly
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59609
Felix Schumacher <fe...@internetallee.de> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #33862|0 |1
is obsolete| |
--- Comment #4 from Felix Schumacher <fe...@internetallee.de> ---
Created attachment 33882
--> https://bz.apache.org/bugzilla/attachment.cgi?id=33882&action=edit
Extract JSON Objects as JSON Strings
My old patch should have worked with your use case already. But to be on the
safe side, I added the case for JSONArray.
--
You are receiving this mail because:
You are the assignee for the bug.
[Bug 59609] JSONPathPostProcessor not evaluating correctly
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59609
--- Comment #1 from Felix Schumacher <fe...@internetallee.de> ---
Created attachment 33861
--> https://bz.apache.org/bugzilla/attachment.cgi?id=33861&action=edit
Extract JSON Objects as JSON Strings
Extract JSON Objects as JSON Strings.
The old implementation gave a Map instance back for the described case.
--
You are receiving this mail because:
You are the assignee for the bug.
[Bug 59609] JSONPathPostProcessor not evaluating correctly
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59609
Philippe Mouawad <p....@ubik-ingenierie.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|HTTP |Main
Hardware|PC |All
--
You are receiving this mail because:
You are the assignee for the bug.
[Bug 59609] JSONPathPostProcessor not evaluating correctly
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59609
Michael Chirlin <mi...@gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
OS| |All
--- Comment #3 from Michael Chirlin <mi...@gmail.com> ---
There is an additional use case in which the extractedObject is an instanceof
JSONArray rather than a Map (JSONObject).
I propose updating the JSONManager stringifyJSONObject the following:
private String stringifyJSONObject(Object obj) {
if (obj instanceof JSONArray) {
return ((JSONArray) obj).toJSONString();
} else if (obj instanceof Map) {
return new JSONObject((Map<String, ?>) obj).toJSONString();
}
return obj == null ? "" : obj.toString(); //$NON-NLS-1$
}
An example would be:
{
"saveInto": [
"string1"
]
}
using JSONPath:
$.saveInto
I'm not sure how you create the attachments or I would do it for you.
--
You are receiving this mail because:
You are the assignee for the bug.
[Bug 59609] JSONPathPostProcessor not evaluating correctly
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59609
Philippe Mouawad <p....@ubik-ingenierie.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |p.mouawad@ubik-ingenierie.c
| |om
--- Comment #5 from Philippe Mouawad <p....@ubik-ingenierie.com> ---
Ok for patch.
Thanks Felix
--
You are receiving this mail because:
You are the assignee for the bug.
[Bug 59609] JSONPathPostProcessor not evaluating correctly
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59609
Felix Schumacher <fe...@internetallee.de> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
--- Comment #6 from Felix Schumacher <fe...@internetallee.de> ---
Date: Tue May 31 18:19:48 2016
New Revision: 1746310
URL: http://svn.apache.org/viewvc?rev=1746310&view=rev
Log:
Format extracted JSON Objects in JSON Post Processor correctly as JSON.
Bugzilla Id: 59609
Added:
jmeter/trunk/test/src/org/apache/jmeter/extractor/TestJSONPostProcessor.java
Modified:
jmeter/trunk/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONManager.java
jmeter/trunk/src/components/org/apache/jmeter/extractor/json/jsonpath/JSONPostProcessor.java
jmeter/trunk/xdocs/changes.xml
--
You are receiving this mail because:
You are the assignee for the bug.
Re: [Bug 59609] New: JSONPathPostProcessor not evaluating correctly
Posted by Felix Schumacher <fe...@internetallee.de>.
Am 21.05.2016 um 05:45 schrieb bugzilla@apache.org:
> https://bz.apache.org/bugzilla/show_bug.cgi?id=59609
>
> Bug ID: 59609
> Summary: JSONPathPostProcessor not evaluating correctly
> Product: JMeter
> Version: 3.0
> Hardware: PC
> Status: NEW
> Severity: normal
> Priority: P2
> Component: HTTP
> Assignee: issues@jmeter.apache.org
> Reporter: michael.chirlin@gmail.com
>
> The JSONPathPostProcessor uses the follow to turn the JSON results to string,
> however if toJSONString isn't used then all of the quotes will be removed.
As I have a problem connecting to bugzilla, I reply here.
Attached is a patch, that extracts JSON objects as JSON strings. Before
JSON Objects would be stringified as Maps.
Regards,
Felix
>
>
> Current Example
>
> With this Code (JSONPostProcessor 166-167):
>
> Object obj = extractedValues.get(0);
> String objAsString = obj != null ? obj.toString() : ""; //$NON-NLS-1$
>
> Run with:
>
> $.context
>
> Against:
>
> {
> "context": {
> "#v": "abc123",
> "#t": "string"
> }
> }
>
> Results in:
>
> {#v: abc123, #t: string}
>
> This is incorrect, all of the quotes have been removed.
>
> It should be replaced with something more like:
>
> String objAsString = "";
> if (extractedValues instanceof JSONArray) {
> objAsString = new JSONObject((Map) extractedValues.get(0)).toJSONString();
> }
>
> Which when tested results:
>
> {"#t":"string","#v":"abc123"}
>
> This obviously needs to be extended for examples where more than one response
> is returned.
>
[Bug 59609] JSONPathPostProcessor not evaluating correctly
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59609
Felix Schumacher <fe...@internetallee.de> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #33861|0 |1
is obsolete| |
--- Comment #2 from Felix Schumacher <fe...@internetallee.de> ---
Created attachment 33862
--> https://bz.apache.org/bugzilla/attachment.cgi?id=33862&action=edit
Extract JSON Objects as JSON Strings
Keep PostProcessor clean by moving the stringification into the JSONManager.
It would be good, if the interface of JSONManager would show, that it returns a
list of Strings. But as it is a public interface it seems to be to late to
change it now.
--
You are receiving this mail because:
You are the assignee for the bug.