Skip to content
Permalink
Browse files
fix: deprecate JacksonFactory in favor of GsonFactory to align with s…
…ecurity team advice (#1216)
  • Loading branch information
elharo committed Jan 12, 2021
1 parent adb2ea4 commit 6b9b6c57734c4917394d0e256e745d69b61b5517
@@ -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;
@@ -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. */
@@ -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;
}
}
}
@@ -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;
@@ -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;
}
@@ -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;
@@ -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;
}
@@ -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
@@ -59,7 +60,7 @@ public String getCurrentName() throws IOException {

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

@Override
@@ -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.