Giter Club home page Giter Club logo

Comments (4)

Assambra avatar Assambra commented on May 19, 2024 1

Thanks again and you can close the issue.

CharacterListModel:
@Getter
@Builder
@EzyArrayBinding
public class CharacterListModel {
    Long id;
    Long accountId;
    String name;
    String sex;
    String race;
    String model;
}

CharacterController:

@EzyDoHandle(Commands.CHARACTER_LIST)
    public void characterList(EzyUser user)
    {
        logger.info("user {} request character list", user.getName());

        responseFactory.newArrayResponse()
                .command(Commands.CHARACTER_LIST)
                .data(
                        convert(characterService.getAllCharacters(user))
                )
                .user(user)
                .execute();
    }

private CharacterListModel[] convert(List<Character> characters)
    {
        CharacterListModel[] chars = new CharacterListModel[characters.size()];

        int i=0;
        for (Character character : characters) {
            CharacterListModel characterListModel = CharacterListModel.builder()
                    .id(character.getId())
                    .accountId(character.getAccountId())
                    .name(character.getName())
                    .sex(character.getSex())
                    .race(character.getRace())
                    .model(character.getModel())
                    .build();

            chars[i] = characterListModel;
            i++;
        }
        return chars;
    }

from ezyfox-server.

tvd12 avatar tvd12 commented on May 19, 2024

You need to add @EzyArrayBinding to Character, you can take a look docs here: https://youngmonkeys.org/ezyfox-library/guides/ezyfox-binding-marshal-unmarshal

from ezyfox-server.

Assambra avatar Assambra commented on May 19, 2024

i've added

@Data
@EzyCollection
@EzyArrayBinding
public class Character {
    @EzyId
    Long id;

    Long accountId;

    String name;
    String sex;
    String race;
    String model;
}

but now i get some error without sending response if i only try to read the List from the database with:

List<Character> chars = characterService.getAllCharacters(user);

public List<Character> getAllCharacters(EzyUser user) {
        Account account = accountRepo.findByField("username", user.getName());

        return characterRepo.findListByField("accountId", account.getId());
    }

Error: Caused by: com.tvd12.ezyfox.binding.exception.EzyReadValueException: can't read value: {accountId=2, race=Humanoid, sex=female, name=Assambra, model=äsldkfälskdfälskdj, _id=1} to: com.assambra.game.common.entity.Character

Error: Caused by: java.lang.ClassCastException: com.tvd12.ezyfox.entity.EzyHashMap cannot be cast to com.tvd12.ezyfox.entity.EzyArray

from ezyfox-server.

tvd12 avatar tvd12 commented on May 19, 2024

Hmm, because you're using this class for the both mongodb entity and response, you should not do that, you need to remove @EzyArrayBinding from the class, create a new response class and convert from entity to response

from ezyfox-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.