4000-520-616
欢迎来到免疫在线!(蚂蚁淘生物旗下平台)  请登录 |  免费注册 |  询价篮
主营:原厂直采,平行进口,授权代理(蚂蚁淘为您服务)
咨询热线电话
4000-520-616
当前位置: 首页 > 新闻动态 >
热卖商品
新闻详情
Dto cannot return data instance of output class(bug)-CSDN问答
来自 : CSDN技术社区 发布时间:2021-03-25

私信 访问主页

\"weixin_39739404\" weixin_39739404 2020-12-02 09:46 首页 开源项目 Dto cannot return data instance of output class(bug)

when I use a output attribute for operation,it can not response instance of output class,what s wrong of it?transformer is like this:

phpfinal class RegistrationOutputTransformer implements DataTransformerInterface * {} public function transform($data, string $to, array $context []) $content $this- authenticationSuccessHandler- handleAuthenticationSuccess($data)- getContent(); $output $this- serializer- deserialize($content,AuthenticatedOutput::class, json // dump($output instanceof AuthenticatedOutput); // this is true return $output; * {} public function supportsTransformation($data, string $to, array $context []): bool return AuthenticatedOutput::class $to $data instanceof User;

and entity

 * registration_by_mail { * method POST , * path /users/register/mail , * input RegistrationMailUserInput::class, * output AuthenticatedOutput::class * },

and output class

phpfinal class AuthenticatedOutput * int private $user_id; * string private $token_type; * int private $expires_in; * string private $refresh_token; * int public function getUserId(): int return $this- user_id; * int $user_id public function setUserId(int $user_id): void $this- user_id $user_id;

the result of output

 : http:\\/\\/phpna.local\\/api\\/docs.jsonld# , hydra : http:\\/\\/www.w3.org\\/ns\\/hydra\\/core# , userId : AuthenticatedOutput\\/userId , tokenType : AuthenticatedOutput\\/tokenType , expiresIn : AuthenticatedOutput\\/expiresIn , refreshToken : AuthenticatedOutput\\/refreshToken  : User , : \\/api\\/users\\/35 

该提问来源于开源项目 api-platform/core

点赞 写回答 收藏 复制链接分享 删除 再等等 结题 再想想 11条回答

私信 访问主页

\"weixin_39739404\" weixin_39739404 3月前

I solved it by set _api_respond false and a custom controller, like this

 * registration_by_mail { * method POST , * path /users/register/mail , * input RegistrationMailUserInput::class, * controller RegistrationCreateByMailCode::class, * _api_respond false * },

and controller

class CreateByMailCode private $authenticationSuccessHandler; private $em; public function __construct(AuthenticationSuccessHandler $authenticationSuccessHandler,ManagerRegistry $em) $this- authenticationSuccessHandler $authenticationSuccessHandler; $this- em $em; public function __invoke(User $data) $em $this- em- getManager(); $em- persist($data); $em- flush(); $content $this- authenticationSuccessHandler- handleAuthenticationSuccess($data)- getContent(); return JsonResponse::fromJsonString($content);

but I still don t know how to use the data in the following format.so I will open a new issue

点赞 评论 复制链接分享

私信 访问主页

\"weixin_39739404\" weixin_39739404 3月前

No, as long as it can output data in the following format, what solution does not matter.

 user_id : 1, access_token : eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE1NTM3ODU0MjAsImV4cCI6MTU1NDE0NTQyMCwicm9sZXMiOlsiUk9MRV9TVVBFUl9BRE1JTiJdLCJ1c2VybmFtZSI6ImFkbWluIn0.cQ-xgBzOrx8o5D5lCtQCCdiy-SmF7ycPbqPkSCdGdsKgEuYtzO0c1ZpXjk9Axqw_JS1PxtMcDRRZkvLfkwuBrqg1HdLRnuTUJiBHwT_b0NXtdgHi8YG-VgfA3Q_syAvfNuByq89x8FNWeBXTH85xenp7XO3uaMcSdfLIvz7atTXabonLs8X9sBs47RsxIzCIm9N4J7pBVwFkLD7oLF451gWbv1zeqlK8CeCHVSKjWWeQgSaaFp--5iVSVtWaHZa0SRrPpANMeNpHWhODjt7RK39hzYfjBsDE0QadQZv3B5fzbI-Op7477ctqG8pwZ1pIhr8KnxtwV3EgY2wYMWB8QXdb4hKVt2wtdMKNYKYb_v5tVpNyEZdquDYja2wp_y6dgJlDoSSSHYfw5KYfvHUcD28JRsBiuceFuZWg-9pSgFHq-iu60TbMrdO6_y7cZO4lDameyE98_GAuue10-ifI2QrpMmKVVfuV984g5mRJHLvArsuj0zKz8X9yHtTqdHEM3ukXP1m98myyLzqWZFXSXqG6uowvaLtgLQCuZeKLqYGO4c8HGw3mjI1M8f1I0b4evn74YJJj1h6mDYW-071Yag9MHRMfodxeL_R128j3csZT_n4i89bx4wfq1FFXF2-vbehLWl9E86t4rRS8F6fnLKHZYE6qfD21aemgwI3-TRA , token_type : Bearer , expires_in : 360000, refresh_token : b71cc02107ebbc7cbba88b1e3419e4e1fe28add04ed517e53dc4d048aa0e1f994a2c926e6e47bf0ac5a69eb411758a76e7cae359a3a35eab99cb854c38a40ed0 

Now I have tried setting normalization_context to false (in the case of still using the output class), and then get the following data

 : http:\\/\\/phpna.local\\/api\\/docs.jsonld# , hydra : http:\\/\\/www.w3.org\\/ns\\/hydra\\/core# , userId : AuthenticatedOutput\\/userId , tokenType : AuthenticatedOutput\\/tokenType , expiresIn : AuthenticatedOutput\\/expiresIn , refreshToken : AuthenticatedOutput\\/refreshToken  : User , : \\/api\\/users\\/21 , userId : 21, tokenType : Bearer , expiresIn : 360000, refreshToken : 4431f1c61eda6995b7849721b61469a4fe59a9c87e83864c64759f7fdd1abd170485906f44fb398897e1b0dabc2a277c1617ccc4bd2fbc11eec3d159a3fae7dc 

But I need to remove other useless data.The last thing I want to know most is how to respond or retrieve the response data in this format returned by json-ld

 : http:\\/\\/phpna.local\\/api\\/docs.jsonld# , hydra : http:\\/\\/www.w3.org\\/ns\\/hydra\\/core# , userId : AuthenticatedOutput\\/userId , tokenType : AuthenticatedOutput\\/tokenType , expiresIn : AuthenticatedOutput\\/expiresIn , refreshToken : AuthenticatedOutput\\/refreshToken  : User , : \\/api\\/users\\/9 
点赞 评论 复制链接分享

私信 访问主页

\"weixin_39680609\" weixin_39680609 3月前

You have to put your data in the Output class inside the transformer ?

点赞 评论 复制链接分享

私信 访问主页

\"weixin_39739404\" weixin_39739404 3月前

from https://github.com/api-platform/core/blob/master/features/main/input_output.feature#L32,my response is fine.but how can I get the real data for client to use from the response data which like this:

 : http:\\/\\/phpna.local\\/api\\/docs.jsonld# , hydra : http:\\/\\/www.w3.org\\/ns\\/hydra\\/core# , userId : AuthenticatedOutput\\/userId , tokenType : AuthenticatedOutput\\/tokenType , expiresIn : AuthenticatedOutput\\/expiresIn , refreshToken : AuthenticatedOutput\\/refreshToken  : User , : \\/api\\/users\\/9 

I just want to get the data of result to be used for client(axios) like follow

 user_id : 1, access_token : eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE1NTM3ODU0MjAsImV4cCI6MTU1NDE0NTQyMCwicm9sZXMiOlsiUk9MRV9TVVBFUl9BRE1JTiJdLCJ1c2VybmFtZSI6ImFkbWluIn0.cQ-xgBzOrx8o5D5lCtQCCdiy-SmF7ycPbqPkSCdGdsKgEuYtzO0c1ZpXjk9Axqw_JS1PxtMcDRRZkvLfkwuBrqg1HdLRnuTUJiBHwT_b0NXtdgHi8YG-VgfA3Q_syAvfNuByq89x8FNWeBXTH85xenp7XO3uaMcSdfLIvz7atTXabonLs8X9sBs47RsxIzCIm9N4J7pBVwFkLD7oLF451gWbv1zeqlK8CeCHVSKjWWeQgSaaFp--5iVSVtWaHZa0SRrPpANMeNpHWhODjt7RK39hzYfjBsDE0QadQZv3B5fzbI-Op7477ctqG8pwZ1pIhr8KnxtwV3EgY2wYMWB8QXdb4hKVt2wtdMKNYKYb_v5tVpNyEZdquDYja2wp_y6dgJlDoSSSHYfw5KYfvHUcD28JRsBiuceFuZWg-9pSgFHq-iu60TbMrdO6_y7cZO4lDameyE98_GAuue10-ifI2QrpMmKVVfuV984g5mRJHLvArsuj0zKz8X9yHtTqdHEM3ukXP1m98myyLzqWZFXSXqG6uowvaLtgLQCuZeKLqYGO4c8HGw3mjI1M8f1I0b4evn74YJJj1h6mDYW-071Yag9MHRMfodxeL_R128j3csZT_n4i89bx4wfq1FFXF2-vbehLWl9E86t4rRS8F6fnLKHZYE6qfD21aemgwI3-TRA , token_type : Bearer , expires_in : 360000, refresh_token : b71cc02107ebbc7cbba88b1e3419e4e1fe28add04ed517e53dc4d048aa0e1f994a2c926e6e47bf0ac5a69eb411758a76e7cae359a3a35eab99cb854c38a40ed0 

it can been get by the instance of output class?if not,what is the output class s response data be used for and how to use it on client(axios in react/vue)?

点赞 评论 复制链接分享

私信 访问主页

\"weixin_39680609\" weixin_39680609 3月前

This looks fine, maybe that you have serializagtion groups that prevent the data from being in the response.

See also:https://github.com/api-platform/core/blob/master/features/main/input_output.feature#L32 https://github.com/api-platform/core/blob/master/tests/Fixtures/TestBundle/Entity/DummyDtoCustom.php

点赞 评论 复制链接分享

私信 访问主页

\"weixin_39739404\" weixin_39739404 3月前

but now I hope to return the instance of outputClass instead of User entity class,ask what to do specifically?dto can not solve it?the features what I want to do is after register user ,app will auto login this user,and return json of custom jwt content.now I just test the output class datatransformer without any serializer, like this

 * {} public function transform($data, string $to, array $context []) $output new AuthenticatedOutput(); $output- setUserId(1); return $output;

but It also can t get the data of AuthenticatedOutput,it show me the follow response

 : http:\\/\\/phpna.local\\/api\\/docs.jsonld# , hydra : http:\\/\\/www.w3.org\\/ns\\/hydra\\/core# , userId : AuthenticatedOutput\\/userId , tokenType : AuthenticatedOutput\\/tokenType , expiresIn : AuthenticatedOutput\\/expiresIn , refreshToken : AuthenticatedOutput\\/refreshToken  : User , : \\/api\\/users\\/9 

no any useful data,please help me,thx

点赞 评论 复制链接分享

私信 访问主页

\"weixin_39680609\" weixin_39680609 3月前

Using the serializer inside the transformer doesn t seem to be a good idea :p.

Anyway, the rest looks good, and about the it s the one from the resource and it should be correct. Indeed, you re still working on theUser , you just output a different representation of the data.

点赞 评论 复制链接分享

私信 访问主页

\"weixin_39739404\" weixin_39739404 3月前

what are you mean of FQCN parameter? I think I have specified the output class, and it works,because transformer s supportsTransformation checked right by code:

 public function supportsTransformation($data, string $to, array $context []): bool return AuthenticatedOutput::class $to $data instanceof User;

but the problem to return data by transform can not return instance of AuthenticatedOutput,and only can return object of User entity.do you can return the output class instance in transform? if not,I think maybe it is a bug?

点赞 评论 复制链接分享

私信 访问主页

\"weixin_39993301\" weixin_39993301 3月前

Does it work when you use the FQCN for the output-parameter?

点赞 评论 复制链接分享

私信 访问主页

\"weixin_39739404\" weixin_39739404 3月前

every time after i change the code to test api point I always clear cache.but it still doesn t work.although I specified output class is AuthenticatedOutput,but api platform can only return : User ,,the result is

 : http:\\/\\/phpna.local\\/api\\/docs.jsonld# , hydra : http:\\/\\/www.w3.org\\/ns\\/hydra\\/core# , userId : AuthenticatedOutput\\/userId , tokenType : AuthenticatedOutput\\/tokenType , expiresIn : AuthenticatedOutput\\/expiresIn , refreshToken : AuthenticatedOutput\\/refreshToken  : User , : \\/api\\/users\\/35 
点赞 评论 复制链接分享

私信 访问主页

\"weixin_39993301\" weixin_39993301 3月前

Just a shot in the dark but have you tried to clear your cache? I had that problem a couple of times and clearing the cache helped.

点赞 评论 复制链接分享 提交 再想想 采纳 为你推荐 理不清VO,BO,DTO,POJO和entity 的使用场景,代码里面要怎么设计呢 java 4个回答后台接口用map还是对象接受参数 springjava 4个回答springboot maven项目使用代码混乱工具proguard的时候,发现类名称变成a\\b\\c了,但是局部变量名称还是原来的。 springandroid 1个回答不可能的类型切换案例:不能有动态类型 interfaceswitch-statement 2个回答具有多个映射符号的结构 dtostructorm 1个回答Json不能解组结构 jsontcpstruct 2个回答Golang将接口{}转换为struct it技术互联网问答IT行业问题计算机技术编程语言问答 1个回答如何使用DTO处理与命令总线方法的关系 php 2个回答spring boot整合rabbitmq ack出现异常 springjava 1个回答可以在php类中创建构造函数吗? htmlfiledtophpclass 2个回答在这种情况下如何使用DTO? architecturedesign-patternsdtophp 1个回答多表查询返回结果应该什么类型 springjavahibernate 3个回答Doctrine将实体发送给DQL的NEW构造函数 dtosymfonyphp 1个回答关于java 反射 getMethods顺序引起的bug spring 0个回答数据库字段是怎么和Dto字段一一对应的呢 it技术互联网问答IT行业问题计算机技术编程语言问答 0个回答webservice客户端采用bean方式调用接口上传DTO给服务端如何看报文 soawebservice 0个回答关于 DTO VS HashMap 领域模型 0个回答Ibatis中的一个“There is no READABLE property named \'uId\' in class \'userinfoPo”错误 ibatis 0个回答WEBLOGIC的BUG??? 关闭的连接 企业应用 0个回答说是找不到实体类,但是是有的,有没有大佬 java 3个回答 点击登录 提问题 欢迎建议意见 . 如何写高质量提问和回答? 采纳榜7天 被采纳次数 ProfSnail 25 幻灰龙 19 qq_34124780 154 coagenth 115 规则边缘 116 GoCityPass新加坡曼谷通票 117 cpp_learner 98 Jack_Yang(数据分析及可视化) 99 我不喜欢这个世界 810 天际的海浪 6 加急问题 500 500 基于tensorflow的模型做预测时,cpu占用率过高,如何降低程序的cpu占用率? 100 unity 设置Animation的culling type 导致游戏崩溃 100 java实现下面两个算法 100 ECDSA加密算法中,签名和验证都是需要时间的,那其时间复杂度怎么用椭圆曲线参数如阶或模p来表示呢? 75 数据库只有myd文件没有frm,myi文件,怎么打开呢 51 利用Adams联合matlab仿真求运动学反解问题 50 labview使用datasocket与c/c#程序的通信 50 python引用xlwings出问题,这个报错什么意思 ,怎么解决,谢谢大佬 50 如何用C语言实现凯撒密码对文本文件(.txt)的读取穷举暴力破解? 50 已知地图GPS坐标点A和坐标点B,获取A点往B点直线走一定距离的坐标点经纬度?

本文链接: http://dtothewp.immuno-online.com/view-740320.html

发布于 : 2021-03-25 阅读(0)
公司介绍
品牌分类
联络我们
服务热线:4000-520-616
(限工作日9:00-18:00)
QQ :1570468124
手机:18915418616
官网:http://