[jboss-jira] [JBoss JIRA] (DROOLS-5234) I use jsonString as the parameter of the function and i get a error:Syntax error on tokens, delete these tokens

xin zhang (Jira) issues at jboss.org
Mon Apr 13 23:55:02 EDT 2020


     [ https://issues.redhat.com/browse/DROOLS-5234?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

xin zhang closed DROOLS-5234.
-----------------------------
    Resolution: Won't Do


> I use jsonString as the parameter of the function and i get a error:Syntax error on tokens, delete these tokens
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: DROOLS-5234
>                 URL: https://issues.redhat.com/browse/DROOLS-5234
>             Project: Drools
>          Issue Type: Bug
>          Components: build
>    Affects Versions: 7.22.0.Final
>            Reporter: xin zhang
>            Assignee: Ant Stephenson
>            Priority: Major
>
> version : `7.22.0.Final`
> - this is my rule:
> ```
> package org.zhangnix.droolsdemo;
> import org.zhangnix.droolsdemo.model.DroolsContext;
> import com.alibaba.fastjson.JSON;
> import com.alibaba.fastjson.JSONObject;
> import java.math.BigDecimal;
> import java.util.List;
> import java.util.Date;
> import java.lang.Boolean;
> import java.lang.String;
> import java.lang.Integer;
> function boolean checkGoodsCount(Integer currentGoodsCount,String jsonString) {
>         JSONObject context = JSON.parseObject(jsonString);
>         int goodsCount = context.getInteger("goodsCount");
>         String compareType = context.getString("compareType");
>         switch (compareType) {
>             case "M":
>                 return currentGoodsCount > goodsCount;
>             case "E":
>                 return currentGoodsCount == goodsCount;
>             case "EM":
>                 return currentGoodsCount >= goodsCount;
>             default:
>                 return false;
>         }
>     }
> rule "Activity conditions"
> when
> $droolsContext:DroolsContext();
> eval(checkGoodsCount($droolsContext.getCurrentGoodsCount(),'{"compareType":"EM","goodsCount":3}'));
> then
> end
> ```
> I use jsonString as the parameter of the function and i get a error:
> > Syntax error on tokens, delete these tokens
> this is my generate java file:
> ```
> public static boolean eval0( org.zhangnix.droolsdemo.model.DroolsContext $droolsContext  
>                                      ) throws java.lang.Exception {
>     Boolean $eval$result$ = ( checkGoodsCount($droolsContext.getCurrentGoodsCount(),"{"compareType":"EM","goodsCount":3}") );
>     return $eval$result$ == null ? false : $eval$result$.booleanValue();
> }
> ```
> When parsing jsonString, there is no backslash (\\) before the quotes. Please tell me what should I do to pass jsonString correctly.



--
This message was sent by Atlassian Jira
(v7.13.8#713008)


More information about the jboss-jira mailing list