Skip to content

docs: PredictTextSentimentAnalysisSample uses unsafe JSON serialization strategy #7561

@wallind

Description

@wallind

Description

The PredictTextSentimentAnalysisSample Java code sample used in documentation here has a flaw as is.

If passed an input containing the " character like how much for 24"x24" pizza boxes it throws an error:

Exception in thread "main" com.google.protobuf.InvalidProtocolBufferException: com.google.gson.stream.MalformedJsonException: Unterminated object at line 1 column 49 path $.content
	at com.google.protobuf.util.JsonFormat$ParserImpl.merge(JsonFormat.java:1347)
	at com.google.protobuf.util.JsonFormat$Parser.merge(JsonFormat.java:477)
	at aiplatform.PredictTextSentimentAnalysisSample.predictTextSentimentAnalysis(PredictTextSentimentAnalysisSample.java:61)
	at aiplatform.PredictTextSentimentAnalysisSample.main(PredictTextSentimentAnalysisSample.java:39)

This can be resolved if the input is properly serialized using com.google.gson which is already included in the sample's dependencies.

Additional Context

I was referred here by @kweinmeister as I'm told this is the new house of what used to live at https://github.com/googleapis/java-aiplatform.

This issue is duplicate of one there: https://github.com/googleapis/java-aiplatform/issues/1097

Metadata

Metadata

Assignees

Labels

api: aiplatformIssues related to the AI Platform API.samplesIssues that are directly related to samples.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions