Tag Archives: protobuf

[Solved] SpringBoot Error: HttpMediaTypeNotSupportedException: Content type ‘application/json‘ not supported

HttpMediaTypeNotSupportedException: Content type ‘application/json;charset=UTF-8’ not supported
Error:

{
    "timestamp": "2021-12-13T11:49:33.305+00:00",
    "status": 415,
    "error": "Unsupported Media Type",
    "path": "/api/v1/product/add"
}

If you are sure that there is no problem with your parameters, it is likely that the problem lies in your @requestbody AAA a
the problem I encounter here is that protobuf is used, but no corresponding bean is injected, resulting in an error. Just add the following code to the application:

PS: protobufmodule is our own extended com fasterxml.jackson.databind.Module class, it’s inconvenient to put it out. You can consult the data by yourself

    @Bean
    ProtobufJsonFormatHttpMessageConverter protobufHttpMessageConverter() {
        return new  ProtobufJsonFormatHttpMessageConverter();
    }

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
        return builder -> builder.serializationInclusion(JsonInclude.Include.NON_NULL)
                .modules(new ProtobufModule(), new JavaTimeModule());
    }

C# Error: Import “google/protobuf/timestamp.proto“ was not found or had errors. [How to Solve]

When using c# as the development language to convert Pb files into CS files, I believe many people will encounter a very difficult problem

The first question: in the protoc3 environment, import timestamp. In the header, import “Google/protobuf/timestamp. Proto”; Exceptions will be thrown when: Google/protobuf/timestamp. Proto “was not found or had errors;

Solution [sharing of original articles by blogger “pamxy”:

(Note: it was found later that it is not necessary to add this directory, because the timestamp.pb.cc file generated by timestamp.proto has been compiled as the source code when compiling libprotobuf.lib file, and libprotobuf.lib is also used in compiling protoc.exe, so it is natural to default that there is already a source code, so there is no need to import it again!)
Just delete the import “Google/protobuf/timestamp. Proto”.

Second question:  ” google.protobuf.Timestamp” is not defined.

Under normal circumstances, there is no need to import google.protobuf.timestamp directly in the protoc3 environment, because in the compilation process, the problem will be read in the Lib file, but if timestamp is called in the file, it is as follows:

It is necessary to call the timestamp file in the header, but bloggers are always prompted during the call  ” google.protobuf.Timestamp” is not defined.

There is really no way, so I have to find the path of this file: timestamp.proto file in protobuf master \ SRC \ Google \ protobuf folder, directly copy the file to the same level directory of the file you want to compile, and then modify the timestamp file in the header. The call path: Import “timestamp. Proto”;

Finally, the file was finally solved…….

The third question: how to call after converting the protocol file into a CS file?

a. Found in referenced project: Tools & gt& gt; Nuget package manager & gt& gt; Nuget package for management solution & gt& gt; Search for “Google. Protocolbuffers” and install

B, directly convert the protoc file into the CS file, and call it in the project.

This small problem is recorded, which is also convenient for you to use as a reference when you encounter this problem.

[go] error prompt proto. Unmarshal: missing method protoreflect

Problem: an error is reported when proto unmarshal is used, and the following information is prompted:

cannot use promoRule (variable of type *db.PromotionRuleSet) as protoreflect.ProtoMessage value in argument to proto.Unmarshal: missing method ProtoReflect (compile)

Solution:
Import package from

"google.golang.org/protobuf/proto"

Change to

"github.com/golang/protobuf/proto"

Python Grpc Error: A file with this name is already in the pool

1.Error:
rank.proto: A file with this name is already in the pool.

[E 210422 14:48:32 flask_server:87] grpc request execution failed, details: Couldn't build proto file into descriptor pool!
    Invalid proto descriptor for file "rank.proto":
      rank.proto: A file with this name is already in the pool.

2. Solutions

(1) Check the current protobuf version, assuming it is 3.12.2
pip3 show protobuf

(2)Uninstall this version
pip uninstall protobuf

(3)Use the following to reinstall the corresponding version
pip install --no-binary protobuf protobuf==3.12.2

Linux CentOS installing protobuf

new version

Google protobuf-3.6.1 is now the latest version, adding new features, see the description

download address https://github.com/protocolbuffers/protobuf/releases

I downloaded the protobuf-all-3.6.1.tar.gz package

new version does not need to execute autogen.sh script, just./configure line

tar ZVXF protobuf-all-3.6.1.tar.gz
CD protobuf-3.6.1

./configure — prefix=/usr/local/

sudo make # take a long time to compile
sudo make check
sudo make install

protoc — version # view version

common errors:
protoc: error while loading Shared libraries: libprotobuf.so.0: cannot open
Shared object file: No such file or directory
solution:
export LD_LIBRARY_PATH = $LD_LIBRARY_PATH:/usr/local/lib