Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-5234

I use jsonString as the parameter of the function and i get a error:Syntax error on tokens, delete these tokens

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Won't Do
    • Affects Version/s: 7.22.0.Final
    • Fix Version/s: None
    • Component/s: build
    • Labels:
      None
    • Docs QE Status:
      NEW
    • QE Status:
      NEW

      Description

      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)
        Unknown macro: { 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.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                anstephe Ant Stephenson
                Reporter:
                zhangnix xin zhang
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: