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

Make it easier to change JsonWriter behaviour

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 3.5.0
    • 3.0.0
    • JSON
    • None
    • Fully Compatible

    Description

      I'm trying to override JsonWriter's doWriteInt64 so that it writes values with just Long.toString() representation.

      In the code, there's:

          @Override
          protected void doWriteInt64(final long value) {
              try {
                  switch (settings.getOutputMode()) {
                      case STRICT:
                          writeStartDocument();
                          writeNameHelper("$numberLong");
                          writer.write(format("\"%d\"", value));
                          writeEndDocument();
                          break;
                      case SHELL:
                          writeNameHelper(getName());
                          if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) {
                              writer.write(format("NumberLong(%d)", value));
                          } else {
                              writer.write(format("NumberLong(\"%d\")", value));
                          }
                          break;
                      default:
                          writeNameHelper(getName());
                          writer.write(Long.toString(value));
                          break;
                  }
              } catch (IOException e) {
                  throwBSONException(e);
              }
          }
      

      but, if I've understood correctly the code, the "default" never gets called, because outputMode will always be either STRICT or SHELL.

      I've tried to override and write my own version (just copy the "default:" code), but writeNameHelper is private and I can't access it.

      Can you make it at least protected?

      Attachments

        Activity

          People

            jeff.yemin@mongodb.com Jeffrey Yemin
            flozano@gmail.com Francisco Alejandro Lozano López
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: