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

Make it easier to change JsonWriter behaviour

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.5.0
    • Affects Version/s: 3.0.0
    • Component/s: JSON
    • None
    • Fully Compatible

      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?

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

              Created:
              Updated:
              Resolved: