the java send entity to redis stream convert to base64

52 views Asked by At

When I tried to send object data to redis stream(Redis Version: 7.0.8) using java(java 11) like this:

package com.dolphin.soa.post.common.mq;

import com.dolphin.soa.post.model.custom.NicknameEdit;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.stream.ObjectRecord;
import org.springframework.data.redis.connection.stream.RecordId;
import org.springframework.data.redis.connection.stream.StreamRecords;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RequiredArgsConstructor
public class StreamMessageProducer {

    private final RedisTemplate<String, NicknameEdit> redisTemplate;

    public void sendRecord(String streamKey, String nickname) {
        NicknameEdit nicknameEdit = new NicknameEdit();
        nicknameEdit.setNickname(nickname);
        ObjectRecord<String, NicknameEdit> record = StreamRecords.newRecord()
                .in(streamKey)
                .ofObject(nicknameEdit)
                .withId(RecordId.autoGenerate());
        RecordId recordId = redisTemplate.opsForStream()
                .add(record);
    }
}

the data in redis shows like this:

{
    "\"X2NsYXNz\"": "\"Y29tLmRvbHBoaW4uc29hLnBvc3QubW9kZWwuY3VzdG9tLlN5c0V2ZW50\"",
    "\"ZGF0YS5fY2xhc3M=\"": "\"Y29tLmRvbHBoaW4uc29hLnBvc3QubW9kZWwuY3VzdG9tLk5pY2tuYW1lRWRpdA==\"",
}

it looks like the send process automatically convert the object fields to base64. why did this happen? what should I do to fixed this issue? this is the NicknameEdit define:

package com.dolphin.soa.post.model.custom;

import lombok.Data;

import java.io.Serializable;

@Data
public class NicknameEdit implements Serializable {
    /**
     * admin_users.id
     *
     * @mbggenerated
     */
    private Long userId;

    /**
     * admin_users.nickname
     *
     * @mbggenerated
     */
    private String nickname;
}

Is it possible to close the base64 encoding and just send the plain text json string?

0

There are 0 answers