Skip to content

Commit

Permalink
fix: deprecate JacksonFactory in favor of GsonFactory to align with s…
Browse files Browse the repository at this point in the history
…ecurity team advice (#1216)
  • Loading branch information
elharo authored Jan 12, 2021
1 parent adb2ea4 commit 6b9b6c5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonGenerator;
import com.google.api.client.json.JsonParser;
import com.google.api.client.json.JsonToken;
import com.google.api.client.util.Preconditions;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -34,7 +33,9 @@
*
* @since 1.11
* @author Yaniv Inbar
* @deprecated use com.google.api.client.json.GsonFactory instead
*/
@Deprecated
public final class JacksonFactory extends JsonFactory {

/** JSON factory. */
Expand Down Expand Up @@ -96,36 +97,4 @@ public JsonParser createJsonParser(String value) throws IOException {
Preconditions.checkNotNull(value);
return new JacksonParser(this, factory.createJsonParser(value));
}

static JsonToken convert(com.fasterxml.jackson.core.JsonToken token) {
if (token == null) {
return null;
}
switch (token) {
case END_ARRAY:
return JsonToken.END_ARRAY;
case START_ARRAY:
return JsonToken.START_ARRAY;
case END_OBJECT:
return JsonToken.END_OBJECT;
case START_OBJECT:
return JsonToken.START_OBJECT;
case VALUE_FALSE:
return JsonToken.VALUE_FALSE;
case VALUE_TRUE:
return JsonToken.VALUE_TRUE;
case VALUE_NULL:
return JsonToken.VALUE_NULL;
case VALUE_STRING:
return JsonToken.VALUE_STRING;
case VALUE_NUMBER_FLOAT:
return JsonToken.VALUE_NUMBER_FLOAT;
case VALUE_NUMBER_INT:
return JsonToken.VALUE_NUMBER_INT;
case FIELD_NAME:
return JsonToken.FIELD_NAME;
default:
return JsonToken.NOT_AVAILABLE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.api.client.json.jackson2;

import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonGenerator;
import java.io.IOException;
import java.math.BigDecimal;
Expand All @@ -28,14 +29,14 @@
*/
final class JacksonGenerator extends JsonGenerator {
private final com.fasterxml.jackson.core.JsonGenerator generator;
private final JacksonFactory factory;
private final JsonFactory factory;

@Override
public JacksonFactory getFactory() {
public JsonFactory getFactory() {
return factory;
}

JacksonGenerator(JacksonFactory factory, com.fasterxml.jackson.core.JsonGenerator generator) {
JacksonGenerator(JsonFactory factory, com.fasterxml.jackson.core.JsonGenerator generator) {
this.factory = factory;
this.generator = generator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.api.client.json.jackson2;

import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonParser;
import com.google.api.client.json.JsonToken;
import java.io.IOException;
Expand All @@ -30,14 +31,14 @@
final class JacksonParser extends JsonParser {

private final com.fasterxml.jackson.core.JsonParser parser;
private final JacksonFactory factory;
private final JsonFactory factory;

@Override
public JacksonFactory getFactory() {
public JsonFactory getFactory() {
return factory;
}

JacksonParser(JacksonFactory factory, com.fasterxml.jackson.core.JsonParser parser) {
JacksonParser(JsonFactory factory, com.fasterxml.jackson.core.JsonParser parser) {
this.factory = factory;
this.parser = parser;
}
Expand All @@ -49,7 +50,7 @@ public void close() throws IOException {

@Override
public JsonToken nextToken() throws IOException {
return JacksonFactory.convert(parser.nextToken());
return convert(parser.nextToken());
}

@Override
Expand All @@ -59,7 +60,7 @@ public String getCurrentName() throws IOException {

@Override
public JsonToken getCurrentToken() {
return JacksonFactory.convert(parser.getCurrentToken());
return convert(parser.getCurrentToken());
}

@Override
Expand Down Expand Up @@ -112,4 +113,36 @@ public double getDoubleValue() throws IOException {
public long getLongValue() throws IOException {
return parser.getLongValue();
}

private static JsonToken convert(com.fasterxml.jackson.core.JsonToken token) {
if (token == null) {
return null;
}
switch (token) {
case END_ARRAY:
return JsonToken.END_ARRAY;
case START_ARRAY:
return JsonToken.START_ARRAY;
case END_OBJECT:
return JsonToken.END_OBJECT;
case START_OBJECT:
return JsonToken.START_OBJECT;
case VALUE_FALSE:
return JsonToken.VALUE_FALSE;
case VALUE_TRUE:
return JsonToken.VALUE_TRUE;
case VALUE_NULL:
return JsonToken.VALUE_NULL;
case VALUE_STRING:
return JsonToken.VALUE_STRING;
case VALUE_NUMBER_FLOAT:
return JsonToken.VALUE_NUMBER_FLOAT;
case VALUE_NUMBER_INT:
return JsonToken.VALUE_NUMBER_INT;
case FIELD_NAME:
return JsonToken.FIELD_NAME;
default:
return JsonToken.NOT_AVAILABLE;
}
}
}

0 comments on commit 6b9b6c5

Please sign in to comment.