[go: nahoru, domu]

Skip to content

Commit

Permalink
http: allow no input with Void.class parsed type
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaniv Inbar committed Apr 19, 2013
1 parent e3f9690 commit e8c4cab
Show file tree
Hide file tree
Showing 10 changed files with 402 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ public final <T> T parse(Class<T> destinationClass) throws IOException {
@Beta
public final <T> T parse(Class<T> destinationClass, CustomizeJsonParser customizeParser)
throws IOException {
startParsing();
@SuppressWarnings("unchecked")
T result = (T) parse(destinationClass, false, customizeParser);
return result;
Expand Down Expand Up @@ -353,7 +352,9 @@ public Object parse(Type dataType, boolean close) throws IOException {
public Object parse(Type dataType, boolean close, CustomizeJsonParser customizeParser)
throws IOException {
try {
startParsing();
if (!Void.class.equals(dataType)) {
startParsing();
}
return parseValue(null, dataType, new ArrayList<Type>(), null, customizeParser);
} finally {
if (close) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
*
* @author rmistry@google.com (Ravi Mistry)
* @since 1.11
* @deprecated (scheduled to be removed in 1.16) Use
* {@link com.google.api.client.testing.json.MockJsonFactory}
*/
@Deprecated
@Beta
public class MockJsonFactory extends JsonFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
*
* @author rmistry@google.com (Ravi Mistry)
* @since 1.11
* @deprecated (scheduled to be removed in 1.16) Use
* {@link com.google.api.client.testing.json.MockJsonGenerator}
*/
@Deprecated
@Beta
public class MockJsonGenerator extends JsonGenerator {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
*
* @author rmistry@google.com (Ravi Mistry)
* @since 1.11
* @deprecated (scheduled to be removed in 1.16) Use
* {@link com.google.api.client.testing.json.MockJsonParser}
*/
@Deprecated
@Beta
public class MockJsonParser extends JsonParser {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @since 1.11
* @author rmistry@google.com (Ravi Mistry)
*/
@Deprecated
@com.google.api.client.util.Beta
package com.google.api.client.testing.http.json;

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

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

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.util.Beta;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;

/**
* {@link Beta} <br/>
* Mock for {@link JsonFactory}.
*
* <p>
* Implementation is thread-safe.
* </p>
*
* @author rmistry@google.com (Ravi Mistry)
* @since 1.15 (since 1.11 as com.google.api.client.testing.http.json.MockJsonFactory)
*/
@Beta
public class MockJsonFactory extends JsonFactory {

@Override
public JsonParser createJsonParser(InputStream in) throws IOException {
return new MockJsonParser(this);
}

@Override
public JsonParser createJsonParser(InputStream in, Charset charset) throws IOException {
return new MockJsonParser(this);
}

@Override
public JsonParser createJsonParser(String value) throws IOException {
return new MockJsonParser(this);
}

@Override
public JsonParser createJsonParser(Reader reader) throws IOException {
return new MockJsonParser(this);
}

@Override
public JsonGenerator createJsonGenerator(OutputStream out, Charset enc) throws IOException {
return new MockJsonGenerator(this);
}

@Override
public JsonGenerator createJsonGenerator(Writer writer) throws IOException {
return new MockJsonGenerator(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

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

import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonGenerator;
import com.google.api.client.util.Beta;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;

/**
* {@link Beta} <br/>
* Mock for {@link JsonGenerator}.
*
* <p>
* Implementation is thread-safe.
* </p>
*
* @author rmistry@google.com (Ravi Mistry)
* @since 1.15 (since 1.11 as com.google.api.client.testing.http.json.MockJsonGenerator)
*/
@Beta
public class MockJsonGenerator extends JsonGenerator {

private final JsonFactory factory;

MockJsonGenerator(JsonFactory factory) {
this.factory = factory;
}

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

@Override
public void flush() throws IOException {
}

@Override
public void close() throws IOException {
}

@Override
public void writeStartArray() throws IOException {
}

@Override
public void writeEndArray() throws IOException {
}

@Override
public void writeStartObject() throws IOException {
}

@Override
public void writeEndObject() throws IOException {
}

@Override
public void writeFieldName(String name) throws IOException {
}

@Override
public void writeNull() throws IOException {
}

@Override
public void writeString(String value) throws IOException {
}

@Override
public void writeBoolean(boolean state) throws IOException {
}

@Override
public void writeNumber(int v) throws IOException {
}

@Override
public void writeNumber(long v) throws IOException {
}

@Override
public void writeNumber(BigInteger v) throws IOException {
}

@Override
public void writeNumber(float v) throws IOException {
}

@Override
public void writeNumber(double v) throws IOException {
}

@Override
public void writeNumber(BigDecimal v) throws IOException {
}

@Override
public void writeNumber(String encodedValue) throws IOException {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (c) 2013 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

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

import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonParser;
import com.google.api.client.json.JsonToken;
import com.google.api.client.util.Beta;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;

/**
* {@link Beta} <br/>
* Mock for {@link JsonParser}.
*
* <p>
* Implementation is thread-safe.
* </p>
*
* @author rmistry@google.com (Ravi Mistry)
* @since 1.15 (since 1.11 as com.google.api.client.testing.http.json.MockJsonParser)
*/
@Beta
public class MockJsonParser extends JsonParser {

private boolean isClosed;

private final JsonFactory factory;

MockJsonParser(JsonFactory factory) {
this.factory = factory;
}

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

@Override
public void close() throws IOException {
isClosed = true;
}

@Override
public JsonToken nextToken() throws IOException {
return null;
}

@Override
public JsonToken getCurrentToken() {
return null;
}

@Override
public String getCurrentName() throws IOException {
return null;
}

@Override
public JsonParser skipChildren() throws IOException {
return null;
}

@Override
public String getText() throws IOException {
return null;
}

@Override
public byte getByteValue() throws IOException {
return 0;
}

@Override
public short getShortValue() throws IOException {
return 0;
}

@Override
public int getIntValue() throws IOException {
return 0;
}

@Override
public float getFloatValue() throws IOException {
return 0;
}

@Override
public long getLongValue() throws IOException {
return 0;
}

@Override
public double getDoubleValue() throws IOException {
return 0;
}

@Override
public BigInteger getBigIntegerValue() throws IOException {
return null;
}

@Override
public BigDecimal getDecimalValue() throws IOException {
return null;
}

/**
* Returns whether {@link #close()} was called.
*
* @since 1.15
*/
public boolean isClosed() {
return isClosed;
}
}
Loading

0 comments on commit e8c4cab

Please sign in to comment.