Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-57

JSON serialize can't handle regex patterns

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 1.1
    • 1.0
    • None
    • None
    • All

    Description

      I generally log all queries in my development environment, but can't log queries involving regular expressions withour getting a "json can't serialize type " exception thrown.

      I've modified a copy of the source code to include:

      if (o instanceof Pattern)

      { buf.append("/").append(o.toString()).append("/").append(Bytes.patternFlags( ((Pattern)o).flags() )); return; }

      just before the throw at the end of serialize(Object,StringBuilder) in JSON.java and it seems to do the job. I'm not sure if you need an equivalent section in parse (since I'm not sure when json gets parsed)

      I also added a rudmentary unit test in JSONTest.java:

      @org.testng.annotations.Test
      public void testPattern()

      { Pattern pattern = Pattern.compile("^Hello$", Pattern.CASE_INSENSITIVE); assertEquals("/^Hello$/i", JSON.serialize(pattern)); }

      I would try to commit a patch, but I've never done that before, and I use windows and git thinks I've changed file permissions on several of the files.

      Attachments

        Activity

          People

            eliot Eliot Horowitz (Inactive)
            keithbranton Keith Branton
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: