public void toJSON(final JsonGenerator generator) throws IOException {
    generator.writeStartObject();

    /*
     * mandatory:
     */
    generator.writeStringField("layer", this.layer);
    if (this.errorCode != CODE_ERROR && this.hotspots.size() < 1) {
      this.errorString = "No POI found. Please increase the search range to try again.";
      this.errorCode = CODE_ERROR;
    }
    generator.writeStringField("errorString", this.errorString);
    generator.writeNumberField("errorCode", this.errorCode);

    // paging is not implemented yet
    generator.writeBooleanField("morePages", this.morePages);
    if (this.nextPageKey != null) {
      generator.writeStringField("nextPageKey", this.nextPageKey);
    } else {
      generator.writeNullField("nextPageKey");
    }
    // generator.writeNumberField("refreshInterval", 3600);
    // generator.writeNumberField("refreshDistance", 50);
    // generator.writeBooleanField("fullRefresh", false);
    // actions for the entire layer:
    // http://layar.com/documentation/browser/api/getpois-response/actions/
    if (this.errorCode == CODE_OK)
      this.showMessage = "You got " + this.hotspots.size() + " hits in the area around you!";
    generator.writeStringField("showMessage", this.showMessage);
    // deletedHotspots
    // animations
    // showDialog: title, description, iconURL, actions
    generator.writeNullField("biwStyle");

    /*
     * hotspots (mandatory):
     */
    createHotspots(generator);

    generator.writeEndObject();
  }
  /**
   * "hotspots": [{
   *
   * <p>"id": "test_1",
   *
   * <p>"anchor": { "geolocation": { "lat": 52.3729, "lon": 4.93 } },
   *
   * <p>"text": { "title": "The Layar Office", "description": "The Location of the Layar Office",
   * "footnote": "Powered by Layar" },
   *
   * <p>"imageURL": "http:\/\/custom.layar.nl\/layarimage.jpeg", }
   *
   * <p>]
   *
   * <p>See http://layar.com/documentation/browser/api/getpois-response/hotspots/
   *
   * @param generator
   * @param hotspots2
   * @throws IOException
   * @throws JsonGenerationException
   */
  private void createHotspots(JsonGenerator generator) throws JsonGenerationException, IOException {
    generator.writeFieldName("hotspots");
    generator.writeStartArray();
    for (Hotspot poi : this.hotspots) {

      generator.writeStartObject();
      generator.writeStringField("id", poi.id);

      // generator.writeFieldName("actions");
      // generator.writeStartArray();
      // if (layarPOI.actions != null) {
      // for (final LayarAction layarAction : layarPOI.actions) {
      // layarAction.toJSON(generator);
      // }
      // }
      // generator.writeEndArray();

      generator.writeObjectFieldStart("anchor");
      generator.writeObjectFieldStart("geolocation");
      generator.writeNumberField("lat", poi.lat);
      generator.writeNumberField("lon", poi.lon);
      generator.writeNumberField("alt", poi.alt);
      generator.writeEndObject();
      generator.writeEndObject();

      // generator.writeNumberField("distance", layarPOI.distance);
      // generator.writeNumberField("type", layarPOI.type);
      // generator.writeStringField("title", layarPOI.title);
      generator.writeObjectFieldStart("text");
      generator.writeStringField("title", poi.title);
      generator.writeStringField("description", poi.description);
      generator.writeStringField("footnote", "Service URL: ...");
      generator.writeEndObject();

      generator.writeStringField("attribution", poi.attribution);
      if (poi.imageURL != null) {
        generator.writeStringField("imageURL", poi.imageURL.toString());
      } else {
        generator.writeNullField("imageURL");
      }
      generator.writeEndObject();
    }
    generator.writeEndArray();
  }