Skip to content

Commit

Permalink
jakartaee#340 - [api] Add support for 'pre-encoded keys'
Browse files Browse the repository at this point in the history
  • Loading branch information
rbygrave committed Dec 14, 2021
1 parent 2da545b commit e83c574
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions api/src/main/java/jakarta/json/spi/JsonProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ private static void checkPackageAccess(String className) {
*/
public abstract JsonGeneratorFactory createGeneratorFactory(Map<String, ?> config);

/**
* Creates a generator key for the given JSON name.
* The {@code JsonGenerator.Key} is immutable and can be held and reused.
* This generator key is optimised for use to writing keys via {@code JsonGenerator}
* by being escaped and encoded when compared to using {@code String} keys.
*
* @param key The JSON name
* @return The JSON generator key
*/
public abstract JsonGenerator.Key createGeneratorKey(String key);

/**
* Creates a JSON reader from a character stream.
*
Expand Down
12 changes: 12 additions & 0 deletions api/src/main/java/jakarta/json/stream/JsonGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,4 +540,16 @@ public interface JsonGenerator extends Flushable, /*Auto*/Closeable {
@Override
void flush();

/**
* A JSON name that can be optimised for writing by a {@code JsonGenerator}.
*/
interface Key {

/**
* Return the key as escaped character array.
*
* @return the key in escaped character array.
*/
char[] toCharArray();
}
}

0 comments on commit e83c574

Please sign in to comment.