[ https://issues.apache.org/jira/browse/OFBIZ-5790?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14180187#comment-14180187 ] Jacopo Cappellato commented on OFBIZ-5790: ------------------------------------------ I agree with [~[hidden email]] about the fact that we can use this task (and this feature/requirement) to start cleaning and refactoring the existing home-grown JSON code. In order to achieve this goal, I started reviewing the existing code and some of the open Jira tickets that could be useful. Here are my initial findings: # the main mechanism we have to return the *result* of a service call in JSON is the CommonEvents.jsonResponseFromRequestAttributes(...) method that is associated to {code} <request-map uri="json"> <security direct-request="false"/> <event type="java" path="org.ofbiz.common.CommonEvents" invoke="jsonResponseFromRequestAttributes"/> <response name="success" type="none"/> </request-map>{code} and can be used with a request like:{code} <request-map uri="createExampleAjax"> <security https="true" auth="true"/> <event type="service" invoke="createExample"/> <response name="success" type="request" value="json"/> <response name="error" type="request" value="json"/> </request-map>{code} the jsonResponseFromRequestAttributes(...) method generates the JSON response using the net.sf.json package i.e. the JSON-lib product (http://json-lib.sourceforge.net); the latest release of this product is 2010-12-14 # an additional dependency on JSON-lib is represented by the toJsonObjectList(...) methods that are defined in the following classes: EbayStoreOptions, HumanResEvents, CategoryServices, ImageManagementServices, ProductStoreEvents; I didn't review these methods closely but we should probably refactor them to use the same method defined in a central place (base component) # then we have the code (parser) in org.ofbiz.base.json that depends on JavaCC; the only dependency we have on org.ofbiz.base.json is from JSONConverters that implements a ConverterLoader for the conversion from the org.ofbiz.base.json.JSON class to List, Map, Set, Short, Byte, Integer, Long, Boolean, Float, Double; I don't think this code is used at all, nor I know how to use it Any hint about #3? how to use it and if it is used? After this initial review, a draft plan could be (pending feedback from others): # create a new JSON util class under org.ofbiz.base.json and move there the implementation of the toJsonObjectList(...) and of the jsonResponseFromRequestAttributes(...) methods # implement there also the method proposed in this patch # convert the code in the new util class from JSON-lib to Jackson # remove the JSON parser in org.ofbiz.base.json and the JSONConverters; # remove the JSON-lib jar > Json string parameters as a service input are not recognized by OFBiz ServiceEventHandler. > ------------------------------------------------------------------------------------------ > > Key: OFBIZ-5790 > URL: https://issues.apache.org/jira/browse/OFBIZ-5790 > Project: OFBiz > Issue Type: Improvement > Affects Versions: Trunk > Reporter: Amardeep Singh Jhajj > Priority: Minor > Attachments: OFBIZ-5790.patch, jackson-annotations-2.4.0.jar, jackson-core-2.4.2.jar, jackson-databind-2.4.2.jar > > > I was trying to pass the Json string as a input to a service, but is not recognized by ServiceEventHandler. > Example Json String- {"faciltyId": "WebStoreWarehouse"} > I worked on this issue and attached a patch here. Here I have used Jackson Json library for parsing. -- This message was sent by Atlassian JIRA (v6.3.4#6332) |
Free forum by Nabble | Edit this page |